A man came to the Prophet ﷺ while he was relieving himself and greeted him with the salaam, but the Prophet ﷺ did not return the greeting until he had performed ablution. He then apologized to the man, saying, "I disliked mentioning the name of Allah except in a state of purity."
أنه أتى النبي ﷺ وهو يبول، فسلم عليه، فلم يرد عليه حتى توضأ، ثم اعتذر إليه فقال: إني كرهت أن أذكر الله عز وجل إلا على طهارة.
Abu Dawud (17), Nasai (38), and Ibn Majah (350) narrated it, and Ibn Khuzayma (206), Ibn Hibban (803), and Hakim (1/167) graded it sahih, all of them through the route of Saeed bin Abu Aruba, from Qatada, from Hasan, from Hudayn bin Munzir, from Muhajir bin Qunfudh, who said, and then he related the hadith. The wording given is that of Abu Dawud and Nasai, while with the others the wording is, he said, "I came to the Prophet ﷺ while he was performing wudu, and I greeted him with salam, but he did not return the greeting. When he finished his wudu he said, 'Nothing kept me from returning your greeting except that I was not in a state of wudu.'"It appears that this version is abridged, with the phrase "while he was urinating" having been omitted from it. Its chain of transmission is sahih. Saeed bin Abu Aruba is a trustworthy and reliable narrator, though he became confused in his later years, and Abdul-Ala bin Abdul-Ala narrated from him before this confusion set in, as mentioned in some sources. Hasan here is Hasan Basri, the well-known imam, though he used to practice tadlis in narrating from the companions. Hudayn, with a dotted dad and in diminutive form, bin Munzir bin Harith Raqashi is among the trustworthy narrators of the generation following the companions, so it is most likely that he heard directly from him.The hadith indicates that mentioning Allah while in a state of ritual purity is preferable, not that doing so without purity was disliked, for it has been established as sahih that the Prophet ﷺ used to mention Allah at all times.