The child belongs to the owner of the bed, and no consideration is given to his resemblance to anyone else
It is narrated from Abu Hurayrah (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.”
[Bukhari: 6818, Kitab al-Hudud: Bab li-l-‘Ahir al-Hajar, Muslim: 1458, Tirmidhi: 1157, Nasa’i: 180/6, Ibn Majah: 2006, Darimi: 152/2, Bayhaqi: 412/7, Humaydi: 1085, ‘Abd al-Razzaq: 443/7, Ahmad: 239/2]
‘Aishah (may Allah be pleased with her) narrates that ‘Utbah bin Abi Waqqas (at the time of his death, in the Jahiliyyah) had made a will to his brother (Sa’d bin Abi Waqqas, may Allah be pleased with him) that he should take into his custody the child born of the slave woman of Zam’ah. ‘Utbah had said that he would be his son. So when the Messenger of Allah ﷺ entered Makkah at the conquest of Makkah, Sa’d bin Abi Waqqas (may Allah be pleased with him) took that child and came into the presence of the Messenger of Allah ﷺ, and ‘Abd bin Zam’ah also came with him. Sa’d bin Abi Waqqas (may Allah be pleased with him) said: this is my brother’s son. My brother made a will that he is his son. But ‘Abd bin Zam’ah said: O Messenger of Allah! This is my brother, the son of (my father) Zam’ah, because he was born on his bed. The Prophet ﷺ looked at the son of Zam’ah’s slave woman, and he did indeed resemble (Sa’d’s brother) ‘Utbah bin Abi Waqqas. But the Messenger of Allah ﷺ decided (in accordance with the law of the Shari’ah): “O ‘Abd bin Zam’ah! You keep this child, he is your brother, because he was born on your father’s bed.” And he said to Sawdah (may Allah be pleased with her) (who was the daughter of Zam’ah): “Observe hijab from this boy,” because the Prophet ﷺ had noticed in the boy a resemblance to ‘Utbah bin Abi Waqqas.
[Bukhari: 4303, Kitab al-Maghazi: Bab, Muslim: 1457, Muwatta: 739/2, Ahmad: 129/6, Abu Dawud: 237, Nasa’i: 3684, Ibn Majah: 2004, Darimi: 152/2]