What is the ruling on calling an illegitimate child after the father?
Question

If a man commits zina with an unmarried woman, and this zina results in the birth of a child, is it permissible for him to call the child after himself?
Praise be to Allah.The scholars are unanimously agreed that the bed is the basic principle in establishing lineage. What is meant by the bed is marriage between the man and the woman.
However the scholars differed with regard to the zaani if he wants to acknowledge his illegitimate child and call him after himself: does that prove the child’s lineage in shar‘i terms, or not? There are two well-known views:
1. That the illegitimate child is not to be attributed to the zaani even if he acknowledges him and names him after himself.
This is the view of most of the scholars of the four madhhabs, and of the Zaahiris (literalists) and others.
Based on this view, the illegitimate child – whether male or female – is not to be attributed to the zaani and is not to be described as his child; rather he is to be attributed to his mother, and he is a mahram to her and inherits from her like her other children.
Fatwas were issued on the basis of this view by Shaykh Ibn Ibraaheem, as in his Fataawa (11/146); Shaykh Ibn Baaz, as in Majmoo‘ al-Fataawa (18/124); and by the Standing Committee (al-Lajnah ad-Daa’imah, 20/387).
That is because the Prophet (blessings and peace of Allah be upon him) said: “The child is to be attributed to the bed (i.e., to the husband) and the adulterer deserves nothing.” Agreed upon. The relevant point here is that the Prophet (blessings and peace of Allah be upon him) did not describe the child as belonging to anyone other than the bed (i.e., the husband), and he said that the adulterer did not deserve anything at all. Attributing the child to the adulterer is attributing the child to someone other than the husband.
The words: “The child is to be attributed to the husband” imply that attribution of the child is to be to the marriage only.
2. That if the zaani acknowledges his illegitimate child, then he is to be attributed to him.
This is the view of ‘Urwah ibn az-Zubayr, Sulaymaan ibn Yasaar, al-Hasan al-Basri, Ibn Sireen, Ibraaheem an-Nakha‘i, and Ishaaq ibn Raahawayh, as was narrated from them by Ibn Qudaamah in al-Mughni (9/123)
This view was favoured by Shaykh al-Islam Ibn Taymiyah (may Allah have mercy on him) and his student Ibn al-Qayyim.
Among contemporary scholars it was also favoured by Shaykh Muhammad Rasheed Rida in Tafseer al-Manaar (4/382), and by Shaykh Ibn ‘Uthaymeen (may Allah have mercy on him), as in ash-Sharh al-Mumti‘ (12/127).
That is because this child was born from his sperm, so he is his son in reality, and there is no clear, sound, shar‘i evidence to indicate that he should not be attributed to him.
With regard to the hadith “The child is to be attributed to the bed (i.e., to the husband) and the adulterer deserves nothing”, it refers to the case where there is a marriage, and the issue under discussion here has to do with a case where there is no marriage.
This is supported by what is mentioned in the story of the devoted worshipper Jurayj, when he spoke to the child whose mother had committed zina with the shepherd: “He said: ‘Who is your father, O child?’ The child said: ‘The shepherd.’” Agreed upon.
The speech of this infant was by way of a miracle and extraordinary event bestowed by Allah, and he stated that the shepherd was his father, even though the relationship was one of zina. This proves that paternity may be attributed to the zaani.
Moreover, the Lawgiver seeks to protect lineages and take care of children, and to give them the best upbringing and protect them from being lost.
We have previously discussed the matter in detail and explained the different scholarly opinions concerning it, and the evidence for each view, in the answer to question no. 192131.
Conclusion:
The view that it is forbidden or permissible (to attribute an illegitimate child to his father) are two scholarly views that carry weight. This issue is one of the matters that are open to ijtihaad, so every case should be examined on its own merits. If the child will miss out on some religious or worldly interests (by not being attributed to his father), then we should adopt the view that it is permissible to attribute him to his father, in the interest of protecting him and ensuring that he will be taken care of, which is a legitimate shar‘i interest.
And Allah knows best.