Abu Maymuna Salma reported,

While I was sitting with Abu Hurairah, a Persian woman came with a son of hers, and both she and her husband were claiming him. Her husband had divorced her.She said, "Abu Hurairah," speaking in Persian, "my husband wants to take my son away."Abu Hurairah said, replying to her in Persian as well, "Cast lots over him."Then her husband came and said, "Who is disputing with me over my child?"Abu Hurairah said, "By Allah, I would not say this except that I heard a woman who came to the Messenger of Allah ﷺ while I was sitting with him. She said, 'Messenger of Allah, my husband wants to take my son away, though he has drawn water for me from the well of Abu Inabah and has been good to me.'The Messenger of Allah ﷺ said, 'Cast lots over him.'Her husband said, 'Who is disputing with me over my child?'The Prophet ﷺ said to the boy, 'This is your father, and this is your mother. Take whichever of their hands you wish.'So he took his mother's hand, and she went off with him."

Azami 6586

Sahih

عن أبي ميمونة سلمى- مولى من أهل المدينة، رجل صدق- قال

بينما أنا جالس مع أبي هريرة، جاءت امرأة فارسية معها ابن لها فادعياه. وقد طلقها زوجها فقالت: يا أبا هريرة- ورطنت بالفارسية- زوجي يريد أن يذهب بابني؟ فقال أبو هريرة: استهما عليه. ورطن لها بذلك. فجاء زوجها فقال: من يحاقني في ولدي؟ فقال أبو هريرة: اللهم إني لا أقول هذا إلا أني سمعت امرأة جاءت إلى رسول الله ﷺ وأنا قاعد عنده- فقالت: يا رسول الله! إن زوجي يريد أن يذهب بابني، وقد سقاني من بئر أبي عنبة، وقد نفعني. فقال رسول الله ﷺ: استهما عليهفقال زوجها: من يحاني في ولدي؟ فقال النبي ﷺ: هذا أبوك، وهذه أمك، فخذ بيد أيهما شئت فأخذ بيد أمه فانطلقت به.

الأعظمي 6586صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Divorce
Section
Giving a child the choice between his parents who have separated
Numbering
Jami al-Kamil 6586 (2nd edition)
Azami 6586