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 1502

Sahih

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

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

الأعظمي 1502صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Ghusl
Section
One in a state of major impurity who did not remember he was in that state until after the prayer had been called
Numbering
Jami al-Kamil 1502 (2nd edition)
Azami 1502