The World Federation One Stop Fiqh

Ruling 1148

If while performing prayers one realises that the mosque is impure, in the event that the time remaining is short, he must complete his prayers. However, if there is ample time and purifying the mosque would not break up the prayer, he must purify it while in prayers and then perform the rest of the prayer. If the prayer would be broken up, then in case it is possible to purify the mosque, it is permitted to break the prayer in order to purify it. And if purifying the mosque after prayers is not possible, he must break his prayers, purify the mosque, and then perform prayers.