Sunan Ibn Majah, Book 5, Hadith 418 (Ibn Majah 1220)

It was narrated that Abu Hurairah said:

“The Prophet (ﷺ) came out to pray and said the Takbir, then he gestured to them to wait. He went and took a bath, and his head was dripping with water while he led them in prayer. When he finished he said: ‘I came out to you in a state of sexual impurity, and I forgot until I had started to pray.’”