عَنِ الرِّضَاؑ عَنْ آبَائِهِ عَنْ عَلِيٍّؑ قَالَ قَالَ رَسُولُ اللهِ ﷺ مَنْ مَاتَ وَ لَيْسَ لَهُ اِمَامٌ مِنْ وُلْدِي مَاتَ مِيتَةً جَاهِلِيَّةً وَ يُؤْخَذُ بِمَا عَمِلَ فِي الْجَاهِلِيَّةِ وَ الْاِسْلَامِ
Imam Reza (peace be upon him) narrates from his ancestors from Ali (peace be upon him) that the Messenger of Allah (s.aw.a.) said,
“Whoever dies without knowing his Imam from my progeny, dies the death of paganism. He will be punished for what he did in the jaahiliyyah and Islam.”
Note:
That is, whoever dies without recognizing the Imam of his time, will be raised as a disbeliever in Barzakh as well as the Hereafter. The word ‘my progeny’ indicates that the Imams (peace be upon them) are appointed by Allah and it is not for the people to select them.
This person was an infidel during the jaahiliyyah. Later, he accepted Islam apparently. Tradition says that
عَنِ النَّبِيِّ ﷺ اَنَّهُ قَالَ الْاِسْلَامُ يَجُبُّ مَا قَبْلَهُ
“(Acceptance of) Islam severs the actions (of disbelief) before it.”
He will not be punished for it. But when a person accepts Islam apparently, i.e. he did not believe in Ameerul Momineen (peace be upon him) and Imams (peace be upon him), he is an infidel and will die as one. So, his actions during paganism as well as in Islam will not have any significance and he will be punished for the same in the Hereafter.
References:
1. Behaar al-Anwaar, vol. 23, p. 81, H. 18
2. Oyoon-o-Akhbaar al-Reza (peace be upon him), vol. 2, p. 58, H. 214, Chapter 31