All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad is His slave and Messenger. We ask Allaah to exalt his mention as well as that of his family and all his companions.
On one hand, the jurists stated that the mother loses her right of fostering her children once she remarries another man, and the fostering is transferred thereupon to the relatives who are more deserving of their fostering.
On the other hand, according to the most preponderant opinion of the scholars when a child reaches the age of seven; he is given the choice to choose between staying with his mother or his father. Then the child goes with whomever he had chosen, unless there is an impediment like the mother remarrying or the father being a dissolute person. For more benefit, please refer to Fatwa 84618. This is in general, but as regards the case in question, since the matter was taken to an Islamic court, then the court is more aware of its circumstances. However, if the father or anyone else does not fully agree with the court ruling, he may submit his inquiries to the court or any higher body/authority if any about the ruling (so that they would justify it).
Allaah Knows best.