If the imam must leave during the Prayer due to some reason, for instance, he remembers that he needs to make wudu’ (ablution) or he loses his wudu’ during the Prayer, then he should appoint another to lead the remainder of the Prayer.
Elaborating more on this, we cite what Sheikh Sayyed Sabiq states in his well-known book, Fiqh Us-Sunnah: If the imam must leave during the Prayer due to some reason, for instance, he remembers that he is in need of making ablution or he loses his ablution during the Prayer, then he should appoint another to lead the remainder of the Prayer.
`Amr ibn Maymun said: “I was standing and there was no one between me and `Umar, the morning he was killed, except `Abdullah ibn `Abbas. He had barely pronounced the takbir when he was stabbed and he said: ‘The dog has bitten or killed me.’ `Umar bade `Abdur-Rahman ibn `Awf to lead the Prayer and he led them in a short prayer” (Al-Bukhari).
Sa`id ibn Mansur reported from Abu Razin: “`Ali was praying one day when his nose began to bleed. He took a man by the hand and put him in front of the congregation, and he left.”
Ahmad observes: “If the imam appoints another [it is acceptable] as `Umar and `Ali appointed another. If the people pray individually, [it is acceptable] as in the case of Mu`awiyyah when he was stabbed and the people prayed individually and completed their prayers.”