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) في المنتقى، كراهية التسليم على من يبول.