Mishkat al-Masabih 3318
‘Amr b. Shu'aib, on his father’s authority, told of his grandfather saying:
The Prophet decided regarding one who is treated as a member of a family after the death of his father to whom he is attributed when the heirs say he is one of them, that if he is the child of a slave woman whom the father owned when he had intercourse with her he is included among those who seek his inclusion, but gets none of the inheritance which was previously divided;* he however gets his portion of the inheritance which has not already been divided, but if the father to whom he is attributed had disowned him he is not joined to the heirs. If he is the child of a slave woman whom the father did not possess or of a freewoman with whom he had illicit intercourse, he is not joined to the heirs and does not inherit even if the one to whom he is attributed is the one who claims paternity, for he is a child of fornication whether his mother was free or a slave. 

Abu Dawud transmitted it.

* Mirqat 3:506 explains this as a reference to what had happened in the pre-Islamic period.
وَعَنْ عَمْرِو بْنِ شُعَيْبٍ عَنْ أَبِيهِ عَنْ جَدِّهِ أَنَّ النَّبِيَّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ قضى أَن كل مستحلق استحلق بَعْدَ أَبِيهِ الَّذِي يُدْعَى لَهُ ادَّعَاهُ وَرَثَتُهُ فَقَضَى أَنَّ كُلَّ مَنْ كَانَ مِنْ أَمَةٍ يملكهَا يَوْم أَصَابَهَا فقد لحق بِمن استحلقه وَلَيْسَ لَهُ مِمَّا قُسِمَ قَبْلَهُ مِنَ الْمِيرَاثِ شَيْءٌ وَمَا أَدْرَكَ مِنْ مِيرَاثٍ لَمْ يُقْسَمْ فَلَهُ نَصِيبُهُ وَلَا يَلْحَقُ إِذَا كَانَ أَبُوهُ الَّذِي يُدْعَى لَهُ أَنْكَرَهُ فَإِنْ كَانَ مِنْ أمَةٍ لم يَملِكْها أَو من حُرَّةٍ عَاهَرَ بِهَا فَإِنَّهُ لَا يَلْحَقُ بِهِ وَلَا يَرِثُ وَإِنْ كَانَ الَّذِي يُدْعَى لَهُ هُوَ الَّذِي ادَّعَاهُ فَهُوَ وَلَدُ زِنْيَةٍ مِنْ حُرَّةٍ كَانَ أَوْ أَمَةٍ. رَوَاهُ أَبُو دَاوُدَ