If it so happens that the parents separate, then the mother has a greater right to custody than the father, unless there is reason not to give priority to the mother or there is a reason to give the child the choice in the matter.
The reason why the mother is given priority is that she is the primary caregiver and is the one who breastfeeds the child; she is also better able to care for the child and take care of him. She has more patience than a man in this regard, and has more time than he does, so the mother is given priority in the best interests of the child.
It was reported from ‘Abd-Allaah ibn ‘Umar that a woman said, “O Messenger of Allaah, my womb was a container for this son of mine and my lap was a haven for him, and he drank from my breast, but his father is claiming that he should take him from me.” The Prophet (peace and blessings of Allaah be upon him) said: “You have more right to him (to custody of him) so long as you do not remarry.” (Narrated by Ahmad, 2/182; Abu Dawood, 2276; al-Haakim, 2/225. Classed as Saheeh by al-Haakim).