عن رافع بن سنان أنه أسلَمَ وأَبَتْ امرأتُه أن تُسْلِم، فأتت النبي صلى الله عليه وسلم ، فقالت: ابنتي وهي فَطِيمٌ أو شَبَهُهُ، وقال رافع: ابنتي، قال له النبي صلى الله عليه وسلم : «اقعد ناحية»، وقال لها: «اقعدي ناحية»، قال: «وأقعد الصَبِيَّةَ بينهما»، ثم قال «ادعواها»، فمَالت الصبية إلى أمها، فقال النبي صلى الله عليه وسلم : «اللهم اهدها»، فمالت الصبية إلى أَبيها، فأخذها.
[صحيح] - [رواه أبو داود والنسائي وأحمد]
Rāfi‘ ibn Sinān (may Allah be pleased with him) reported: I embraced Islam, but my wife refused to do so. She went to the Prophet (may Allah's peace and blessings be upon him) and said: "My daughter is weaned or about to be weaned." Rāfi‘ said: "My daughter." The Prophet (may Allah's peace and blessings be upon him) said to the man: "Sit down on this side." And he said to the woman: "Sit down on that side." He then seated the girl between them, and said to them: "Call her." The girl went to her mother and the Prophet (may Allah's peace and blessings be upon him) said: ‘'O Allah, guide her," and the daughter then went to her father, who took her.
Sahih/Authentic. - [An-Nasaa’i]
This Hadīth talks about a mother and father who were disputing about the custody of their daughter in the presence of the Prophet (may Allah's peace and blessings be upon him). The father was a Muslim, but the mother was not. They were arguing about their daughter, so the Prophet (may Allah's peace and blessings be upon him) got the girl to choose between them. She initially chose her mother. However, as the mother was a disbeliever, the Prophet (may Allah's peace and blessings be upon him) prayed that Allah would guide the girl to make the right choice. Allah, the Almighty, answered the Prophet's invocation, and the girl then chose her father. The benefit of the story is that it is not in accordance with divine guidance for a child to be under the care of a disbelieving parent. Having custody means raising a child and protecting him from damage, and the best upbringing is to keep the child's religion intact and the best means of protection is to keep lack of belief away from him. If a child was raised by a disbelieving parent, he would be tempted by them to give up Islam and they would make him leave by teaching him the principles of disbelief and raising him on them. This is the worst harm that can be done to a child, as having custody is meant to protect a child; it is not allowed to be carried out in a manner that involves the destruction of a child or their religion.