The prayer was called and the people formed their rows. The Messenger of Allah ﷺ came out, and when he stood in his place, he remembered that he had not performed the ritual bath. He said to the people, "Stay where you are." Then he returned to his house and came back out to us with water dripping from his head, having bathed, while we remained in our rows.This is the wording of Ibn Harb. In Ayyash's version, he said, "We remained standing, waiting for him, until he came out to us having bathed."
حدثنا عمرو بن عثمان حدثنا محمد بن حرب حدثنا الزبيدي ح و حدثنا عياش بن الأزرق أخبرنا ابن وهب عن يونس ح و حدثنا مخلد بن خالد حدثنا إبراهيم بن خالد إمام مسجد صنعاء حدثنا رباح عن معمر ح و حدثنا مؤمل بن الفضل حدثنا الوليد عن الأوزاعي كلهم عن الزهري عن أبي سلمة
أقيمت الصلاة وصف الناس صفوفهم فخرج رسول الله ﷺ حتى إذا قام في مقامه ذكر أنه لم يغتسل فقال للناس مكانكم ثم رجع إلى بيته فخرج علينا ينطف رأسه وقد اغتسل ونحن صفوف وهذا لفظ ابن حرب وقال عياش في حديثه فلم نزل قياما ننتظره حتى خرج علينا وقد اغتسل
Bukhari reported it in the Book of Adhan, Chapter "May one leave the masjid for a reason?" (Hadith 639, 640), and Muslim in the Book of Masjids, Chapter "When should people stand for prayer?" (Hadith 605), from the narration of Zuhri through this chain. See also Hadith 541.