The Prophet ﷺ said, "The child belongs to the bed, and for the fornicator is the stone."
أخبرنا قتيبة قال حدثنا سفيان عن الزهري عن سعيد وأبي سلمة
أن النبي ﷺ قال الولد للفراش وللعاهر الحجر
Muslim narrated it in the chapter on breastfeeding, the section on "the child belongs to the marriage bed, and avoiding doubtful matters," Hadith 1458, from the hadith of Sufyan bin Uyayna, with the same wording. It is also found in Kubra, Hadith 5676.