Praise be to Allah.
If a person leads some people in prayer then realizes that he did not have wudoo’, the prayer of those who prayed behind him is valid, according to the more correct of the two scholarly opinions, but the prayer of the imam is invalid, and he must repeat it.
Ibn Qudaamah (may Allaah have mercy on him) said: If the imam leads a congregation in prayer and he does not have wudoo’, or he is junub, but he does not realize that he is not in a state of purity, and neither he nor the people praying behind him are aware of it until after they have finished praying, their prayer is valid but the prayer of the imam is invalid. This was narrated from ‘Umar, ‘Uthmaan, ‘Ali and Ibn ‘Umar (may Allaah have mercy on them), and it was the view of Maalik and al-Shaafa’i.
It was narrated from ‘Umar (may Allaah be pleased with him) that he led the people in praying Fajr prayer, then he found some wetness as the result of having had an erotic dream on his garment, so he repeated the prayer but they did not.
‘Uthmaan (may Allaah be pleased with him) led the people in Fajr prayer, then when morning came and the sun had risen, he found traces of janaabah, so he repeated the prayer but he did not tell them to repeat it.
It was narrated that ‘Ali (may Allaah be pleased with him) said: If a person who is junub leads the people in prayer and completes the prayer, I would tell him to do ghusl and repeat the prayer but I would not tell them to repeat it.
It was narrated that Ibn ‘Umar (may Allaah be pleased with him) led them in praying Fajr, then he said that he had prayed without wudoo’, so he repeated it but they did not repeat it.
All these incidents were narrated by al-Athram. End quote from al-Mughni (1/419).
The Standing Committee for Issuing Fatwas was asked about a man who prayed Zuhr and ‘Asr as an imam when he was junub, but he did not know that he was junub.
They replied: You have to repeat Zuhr and ‘Asr after doing ghusl to cleanse yourself of janaabah, and you must hasten to do that. As for those who offered these prayers behind you, they do not have to repeat them, because ‘Umar (may Allaah be pleased with him) led the people in praying Fajr when he was junub and had forgotten about it, so he repeated Fajr but he did not tell those who had offered that prayer behind him to repeat it. And they are excused because they did not know that you did not have wudoo’. End quote.
Fataawa al-Lajnah al-Daa’imah (6/266)
And Allaah knows best .