All praise is due to Allah, and peace and blessings be upon the Messenger of Allah.
One of the essential conditions for the validity of following an imam in prayer is that the follower does not know that the Imam’s prayer is invalid due to a nullifying factor such as impurity. If a person prays behind an imam assuming his prayer is valid, then the follower’s prayer remains valid — even if it is later discovered that the Imam’s prayer was invalid — provided the cause of invalidity was not known at the time and was of a hidden nature.
In this regard, Al-Imam Ba‘shīn Al-Shāfi‘i (may Allah have mercy on him) stated: "A condition for valid following (Iqtida’) is that the follower is not aware of any invalidating factor in the imam’s prayer, such as impurity or anything else unanimously agreed to nullify the prayer, like disbelief or the exposure of one’s private parts. In such a case, the follower would not be considered truly in prayer and would be at fault." [Bushra Al-Karim/pp.334]. He also clarified: "If it later becomes evident that the imam was in a state of impurity or similar condition that is typically hidden, then the follower does not need to repeat the prayer, as there is no fault on his part." [Bushra Al-Karim/pp.337].
This ruling also applies to Friday prayer .i.e. If it is discovered after the prayer that the Imam's purification was invalid (such as having used impure water for Wudu), then: The Imam must repeat the prayer as Dhuhr, not Friday, because he missed a condition for the validity of the prayer. Purification is a necessary condition for both the prayer and, according to the stronger scholarly opinion, for delivering the Friday sermon as well.
The congregation, however, is not required to repeat the prayer, as their prayer was performed in good faith, and the cause of invalidity was not apparent at the time. Further, Al-Imam An-Nawawi (may Allah have mercy on him) said: "Al-Sheikh Abu Hamid and others have stated definitively that if the Friday Imam was in a state of Janabah (major ritual impurity) and the congregation only discovered this after the prayer, their Friday prayer is valid. This was narrated from Al-Imam Al-Shāfi‘i in his book Al-Umm." [Al-Majmu Sharh Al-Muhadhdhab/vol.4/pp.515].
At last, if the Friday prayer was performed in accordance with all apparent conditions and it was only later discovered that the imam was in a state of minor or major impurity, the prayer of the congregation remains valid and there is no need to repeat it. The imam, however, must repeat his prayer as Dhuhr, not Friday prayer. And Allah Almighty Knows Best.