Abu Hurairah reported,

The Prophet ﷺ went out to lead the prayer and pronounced the opening takbir, then he gestured to them to wait. They remained in place while he went off and performed a full bath. He returned with water still dripping from his head and led them in prayer.When he finished, he said, "I came out to you in a state of major ritual impurity. I had forgotten until I was already standing in the prayer."

Ibn Majah 1220

Hasan

حدثنا يعقوب بن حميد بن كاسب حدثنا عبد الله بن موسى التيمي عن أسامة بن زيد عن عبد الله بن يزيد مولى الأسود بن سفيان عن محمد بن عبد الرحمن بن ثوبان

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

خرج النبي ﷺ إلى الصلاة وكبر ثم أشار إليهم فمكثوا ثم انطلق فاغتسل وكان رأسه يقطر ماء فصلى بهم فلما انصرف قال إني خرجت إليكم جنبا وإني نسيت حتى قمت في الصلاة

ابن ماجه 1220حسن
Contents
Reference
Commentary
Ayat
Collection
Sunan Ibn Majah
Book
Establishing prayer and the sunnah regarding it
Chapter
Building upon the prayer
Numbering
Darussalam 1220
Ibn Majah 1220