Abu Hurairah reported,

The prayer was called, and the rows were straightened with everyone standing. The Messenger of Allah ﷺ came out to us, but when he stood in his place of prayer, he remembered that he was in a state of major ritual impurity, so he said to us, "Stay in your places."He then went back, performed the full bath, and returned to us with water still dripping from his head. He pronounced the opening takbir, and we prayed with him.In another narration, "We had straightened the rows before he came out."

Azami 2252

Sahih

عن أبي هريرة قال

أقيمت الصلاة وعدلت الصفوف قياما، فخرج إلينا رسول الله ﷺ، فلما قام في مصلاه ذكر أنه جنب، فقال لنا: مكانكم. ثم رجع فاغتسل، ثم خرج إلينا ورأسه يقطر، فكبر وصلينا معه. وفي رواية: فعدلنا الصفوف قبل أن يخرج.

الأعظمي 2252صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Prayer
Chapter
Leadership
Section
Imam remembering that he is in a state of major ritual impurity after the prayer has been called
Numbering
Jami al-Kamil 2252 (2nd edition)
Azami 2252