In our corpus of ahadith we find very severe narrations against illegitimate childs (walad zina). Beside the known jurisprudential issues that they cannot give a testimony, be a judge, inherit etc some narrations go as far as saying that that they are impure or that they won’t be allowed heaven because heaven is for the pure ones therefore a child born out of an impurity (fornication) cannot enter it.
On the other side, some say that the real walad zina are the enemies of Ahlul Bayt (as), and that some narrations mention that when a child borned out of wedlock accepts the wilayah of Ahlul Bayt (as) he becomes purified of the title of walad zina.

In short, which opinion is closer to the reality ? Can an illegitimate child enter heaven or, as some narrations says he won’t be allowed in in any case, and he is impure.

1- As for hadiths that state an illegitimate person should not be a judge or prayer leader, the aim is to keep society healthy and not normalize adultery. Imagine if there is an important prayer leader and he is illegitimate. It looks bad for the community. People will think “Oh, I guess adultery is not that bad after all…see this leader he is illegitimate. No big deal.” This normalizes it. So to discourage people from committing adultery, Islam prohibits illegitimate children from having such positions. It’s for the overall good of society.

As for the testimony, again it goes back to the issue of normalizing it in society. Islam doesn’t want such people to have an important public position because:

A- It makes adultery normal in society. People will see witnesses in court who are illegitimate and so over time it becomes normal.

B- Islam wants to put pressure on potential adulterous parents: don’t have an illegitimate child because if you do, then you will deny him many privileges. So be wise and don’t

C- Many illegitimate children grow up in bad and corrupt environments, and so it’s safer not to have them assume a very critical role such as witnessing in court

By the way, all this applies to someone who is known to be an illegitimate child. We don’t have to go and investigate such matters.

2- As for an illegitimate child not being eligible to go to heaven, there are some hadiths to that effect, but scholars have different perspectives on them. One perspective is that these narrations are talking about the fate of many of them, not all of them. Naturally, an illegitimate child usually grows up in a corrupt-prone environment—decreasing the chances of him being guided. Just like kids who grow up in bad neighborhoods around gangs. They tend to be aggressive, violent, and criminals. But if the illegitimate child does good and believes in the truth, he can go to heaven. Here’s one hadith in Kafi:

عن ابن أبي يعفور عن الصادق (عليه السلام) قال: ”إن ولد الزنا يُستعمل، إن عمل خيراً جُزِيَ به، وإن عمل شراً جُزِيَ به“. (الكافي ج8 ص238).

Basically the Imam says that if the illegitimate child does good, he will be rewarded for it.

So these hadiths that state they don’t enter heaven are basically warning the parents to not put them in a corrupt environment.