Who has more right to custody in Islam?
Question

After a marriage that lasted for a few years, a man divorced his wife and tried to take the child from her. She is asking who has more right to custody of the child, her or her ex-husband? Especially since she is going to travel to live with her family in another city.
Praise be to Allah.Women have more right to custody of children than men; in principle custody belongs to them, because they are more compassionate and more kind, and they know better how to raise small children, and they are more patient in dealing with the difficulties involved. The mother has more right to custody of her child, whether it is a boy or a girl, so long as she does not re-marry and so long as she meets the conditions of custody. This is according to scholarly consensus.
The conditions of custody are: being accountable (i.e., an adult of sound mind etc.), being free (as opposed to being a slave), being of good character, being a Muslim if the child concerned is a Muslim, and being able to fulfil all obligations towards the child. The mother should not be married to a person who is a stranger (i.e., not related) to the child. If one of these conditions is not fulfilled and there is an impediment such as insanity or having remarried, etc., the woman forfeits the right to custody, but if that impediment is removed, then the right to custody is restored. But it is best to pay attention to the interests of the child, because his rights come first.
The period of custody lasts until the age of discretion and independence, i.e., until the child is able to discern what is what and is independent in the sense that he can eat by himself, drink by himself, and clean himself after using the toilet, etc.
When the child reaches this age, the period of custody ends, whether the child is a boy or a girl. That is usually at the age of seven or eight.
With regard to the effect of travelling on transferring custody, if the parents have separated and are disputing custody, any of the following scenarios may apply to their travelling:
1 – If one of the parents wants to travel without moving, i.e., he or she intends to come back, then the parent who is staying put has more right to the child.
2 – If one of them wants to travel for the purpose of settling there, and the new city or the route is dangerous, then the parent who is staying put has more right to the child.
3 – If one of them wants to move and settle within the same city, and the city and the route is safe,the father has right to the child than the mother, regardless of whether the one who is moving is the father or the mother.
4 – If both parents want to travel to the same place, then the mother should retain custody.
5 – If the place is nearby so that the father and child may see one another every day, then the mother should retain custody.
When the child reaches the age of independence, the period of custody comes to an end, and the period of kafaalah or sponsorship of the young begins, which lasts until the child reaches adolescence or in the case of a girls, starts her periods. Then the period of sponsorship ends and the child is free to make his own choices.
Women’s rights to sponsor children. It appears from the comments of the fuqaha’ that women have the right to sponsor children in general, and that mothers and grandmothers in particular have this right.  But the scholars differed as to who has more right to sponsorship if the parents are in dispute and are both qualified to sponsor the child. The Maalikis and Zaahiris think that the mother has more right to sponsorship of the child, whether it is a boy or a girl. The Hanbalis think that boys should be given a choice, but the father has more right in the case of a girl. The Hanafis think that the father has more right in the case of a boy and the mother has more right in the case of a girl. Perhaps the correct view is that the child should be given a choice if the parents are disputing and they both fulfil the conditions for sponsorship.