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.