It is narrated from Sayyiduna Abdullah bin Amr bin al-As (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him) gave the ruling: "A boy who is attributed to his father after his father's death (that is, after the death of the man, his heirs claim that this is the child of our deceased), the Prophet (peace and blessings be upon him) ruled that the boy is from the slave woman whom the father owned at the time of intercourse, so his lineage will be attributed to the one who claims him. However, whatever inheritance was distributed before he was attributed, he will have no share in it, but whatever inheritance has not been distributed, he will have a share in it. But if the father to whom his lineage is attributed had denied his lineage during his lifetime, then he will not be attributed to him by the claim of the heirs (that is, he will not be considered his child). And if the boy is from a slave woman whom the father did not own, or from a free woman with whom the father committed adultery, then his lineage will never be established from that man (even if the man's heirs attribute the child to him), nor will the child inherit from that (adulterer) man, even if the father claimed during his lifetime that this is my child, because he is a child of adultery, and he will be attributed to his mother's people, whether he was born from a free woman or a slave woman (after all, he is a child of adultery, and will not inherit, nor be included in the lineage)."
Hadith Referenceسنن دارمي / من كتاب الفرائض / 3145
A child born out of adultery (zina) in reality has no connection whatsoever with the man who committed adultery, even if it is from his own sperm.
This hadith can be understood by the following example: Zaid died, and he had a slave woman from whom there was a child. Now, after Zaid’s death, if all or some of his heirs accept that this child is indeed Zaid’s, then that child will be considered Zaid’s child, the lineage (nasab) will be established, and the child will be an heir. Or, if Zaid himself, during his lifetime, acknowledged that this child is his, then too the child will be included in the lineage and will be an heir. However, if Zaid denied it, then neither will the child be an heir nor will he be included in the lineage, even if some of the heirs acknowledge him.
And Allah knows best.
See: Sharh Ibn Majah, the mentioned hadith by Allamah Waheeduz-Zaman Khan rahimahullah ta'ala.