There are narrations from Ahlul Bait in this regard like:
- عن امیرالمؤمنین (ع) لایصلین احدکم خلف المجنون و ولدا الزنا وسائل الشیعة
- مَعْرُوفٍ عَنْ أَبِی جَمِیلَةَ عَنْ سَعْدِ بْنِ طَرِیفٍ عَنِ الْأَصْبَغِ بْنِ نُبَاتَةَ قَالَ سَمِعْتُ أَمِیرَ الْمُؤْمِنِینَ ع یَقُولُ سِتَّةٌ لَا یَنْبَغِی أَنْ یَؤُمُّوا النَّاسَ وَلَدُ الزِّنَا وَ الْمُرْتَدُّ وَ الْأَعْرَابِیُّ بَعْدَ الْهِجْرَةِ وَ شَارِبُ الْخَمْرِ وَ الْمَحْدُودُ وَ الْأَغْلَفُ
- and a narration from Imam Muhammad ibn Ali al-Baqer in which he says don't pray behind 5 types of people one of which is a child out of wedlock.
Plus that is the consensus of Shia scholars on this ruling.
The word Imam means Muqtada, a leader and someone whom others follow and set an example in their works. And the Imam of the congregation is the one whom the group and the congregation set as their role model. Therefore, there should not be a defect in the position of the incumbent, although he himself has not interfered in achieving this defect. To explain that, the fact that an illegitimate child is deprived of some social and spiritual positions such as Imamate of the congregation and the authority of Taqlid, etc., which are the contents of some above mentioned narrations, is because of the nature of these positions and it does not mean deprivation of salvation on the Day of Judgment, for example, a blind person can not be in charge of some positions or a person who is very forgetful can not be a judge even if he has not committed the slightest sin in his life, having a good memory is one of the conditions of a judge. But these deprivations have nothing to do with one's felicity or unhappiness(i.e. bad end), and so is that with the illegitimate child, and our proof is that in the same narrations, the illegitimate child is placed next to the insane and the leper, etc., even though someone is not crazy or is not leper by their own will.
From a social point of view, being an illegitimate is also a kind of defect and does not lead to reputation, because on the one hand, illegitimacy is the product of a shameful act, and on the other hand, most of the illegitimate children have not shown an acceptable record throughout history, and this is certain that in holding some positions, a person should be away from the characteristics and traits that cause hatred and distance from people, even if those characteristics have been imposed on him without authority.