Sunan Ibn Majah, Book 23, Hadith 27 (Ibn Majah 2747)

It was narrated from ‘Amr bin Shu’aib, from his father, from his grandfather that the Messenger of Allah (ﷺ) said:

“Whoever commits adultery with a slave woman or a free woman, his child is illegitimate, and he cannot inherit from him or be inherited from (i.e., this child cannot inherit from him).”