It is narrated from Abdullah bin Umar (may Allah be pleased with them both) that a man passed by the Prophet (ﷺ) while he was urinating. The man greeted the Prophet (ﷺ) with salam, and the Prophet (ﷺ) replied to him. When the man went away, the Prophet (ﷺ) called him back and said: "I replied to your salam only so that you would not say that I greeted the Messenger of Allah (ﷺ) and he did not reply to me. When you see me in this state again, do not greet me with salam. If you do, I will not reply to you."
Hadith Referenceمسند الإمام الشافعي / كتاب الطهارة / 37
Hadith Takhrijإسناده ضعيف جداً لشدة ضعف إبراهيم بن محمد بن أبي يحيى لكن الحديث ورد من طريق غيره عند ابن الجارود: (37) في المنتقى، كراهية التسليم على من يبول.
It is narrated from Ibn Sammah (may Allah be pleased with him) who says: I passed by the Prophet ﷺ while he was urinating. I greeted him with salam, but he did not reply to me until he stood by a wall and scratched it with a stick that he had with him. Then he struck his hand on the wall, wiped his face and hands, and then replied to my salam.
Hadith Referenceمسند الإمام الشافعي / كتاب الطهارة / 38
Hadith Takhrijأخرجه البخاري: التیمم، باب التيمم في الحضر إذا لم يجد الماء وخاف فوت الصلاة: (337).
It is narrated from Sulaiman bin Yasar (may Allah have mercy on him) that the Prophet (ﷺ) went towards Bi’r-e-Jamal to relieve himself. When he returned, a man greeted him with salam, but he did not reply until he wiped his hand on the wall, then he returned the greeting.
Hadith Referenceمسند الإمام الشافعي / كتاب الطهارة / 40
Hadith Takhrijمرسل، فإن سليمان بن يسار تابعي وشيخ الشافعي متروك الحديث، أخرجه البيهقي في معرفة السنن والآثار (120).