It is narrated from Abu Huraira (may Allah be pleased with him) that the Messenger of Allah (ﷺ) said: "The child belongs to the (owner of the) bed, and for the adulterer there are stones."
Hadith Referenceمسند الإمام الشافعي / كتاب عشرة النساء والإيلاء والخلع / 1201
Hadith Takhrijاخرجه البخاري، الحدود، باب للعاهر الحجر (6818) ، (6750) - مسلم ، الرضاع، باب الولد للفراش، وتوقى الشبهات (1458)۔
Narrated from Aisha (may Allah be pleased with her) that Abd bin Zam‘ah and Sa‘d bin Abi Waqqas (may Allah be pleased with them both) brought the case of the son of Zam‘ah’s slave woman to the Messenger of Allah ﷺ. Sa‘d said: “O Messenger of Allah ﷺ! My brother had made a will that when you go to Makkah, look at the child of Zam‘ah’s slave woman and take him, for he is my son.” Abdullah bin Zam‘ah said: “He is my brother and the son of my father’s slave woman, and he was born on my father’s bed.” The Prophet ﷺ saw that the boy clearly resembled ‘Utbah, then said: “O Abdullah bin Zam‘ah! He will go with you, for the child belongs to the (owner of the) bed. (And he ordered Umm al-Mu’minin Sawdah, may Allah be pleased with her): O Sawdah! Observe veil from him.”
Hadith Referenceمسند الإمام الشافعي / كتاب عشرة النساء والإيلاء والخلع / 1202
Hadith Takhrijاخرجه البخاري، البيوع، باب شراء المملوك من الحربي وهبته وعتقه (2218)، (2053) ومسلم، الرضاع، باب الولد للفراش وتوقى الشبهات (1457)۔
Abdullah bin Abi Yazid narrated from his father who said that Umar bin Khattab (may Allah be pleased with him) sent a man to an old man from Banu Zuhrah who lived among our houses. I also went with him to Umar (may Allah be pleased with him), and he asked him about the birth of children in the pre-Islamic period. He said: "The bed would belong to one person and the semen to another (that is, the owner of the bed and the owner of the semen would be different)." Upon this, Umar bin Khattab (may Allah be pleased with him) said: "You have spoken the truth, but the Messenger of Allah (ﷺ) has decided in favor of the owner of the bed."
Hadith Referenceمسند الإمام الشافعي / كتاب عشرة النساء والإيلاء والخلع / 1203