Muhajir bin Qunfud reported,

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."

Azami 1445

Sahih

عن المهاجر بن قنفذ

أنه أتى النبي ﷺ وهو يبول، فسلم عليه، فلم يرد عليه حتى توضأ، ثم اعتذر إليه فقال: إني كرهت أن أذكر الله عز وجل إلا على طهارة.

الأعظمي 1445صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Purification
Section
Disapproval of greeting one who is urinating
Numbering
Jami al-Kamil 1445 (2nd edition)
Azami 1445