Sheikh `Abd al-Wahhâb al-Turayrî, former professor at al-Imâm University in Riyadh
If the imam realizes that he is not in a state of purity during the prayer, he should leave his place and appoint another man from the ranks to step forward and lead the prayer.
All of the worshippers should continue the same prayer in congregation behind the new imam. Their prayer will be still valid.
And Allah knows best.
Source: Islam Today