Praise be to Allah.Praise be to Allaah.
The fuqaha’ are agreed that it is makrooh to give salaams to someone who is relieving himself, and it is also makrooh for him to respond. It was narrated that Abu’l-Jahm al-Ansaari (may Allaah be pleased with him) said: The Messenger of Allaah (blessings and peace of Allaah be upon him) came from the direction of Bi’r Jamal and was met by a man who greeted him with salaam. The Messenger of Allaah (blessings and peace of Allaah be upon him) did not return the greeting until he went to a wall and wiped his face and hands, then he returned the greeting.
Narrated by al-Bukhaari (no. 337) and Muslim (no. 369).
And it was narrated from Ibn ‘Umar that a man passed by when the Messenger of Allaah (blessings and peace of Allaah be upon him) was urinating. He greeted him, but he did not return the greeting. Narrated by Muslim (no. 370).
And it was narrated from al-Muhaajir ibn Qunfudh that he came to the Prophet (blessings and peace of Allaah be upon him) when he was urinating and he greeted him with salaam, but the Prophet (blessings and peace of Allaah be upon him) did not return the greeting until he had done wudoo’, then he apologised to him and said: “I do not like to mention Allaah, may He be glorified and exalted, except in a state of purity.” Narrated by Abu Dawood (17); classed as saheeh by Ibn Hajar in Nataa’ij al-Afkaar, 1/205; and by al-Albaani in Saheeh Abi Dawood.
Ibn al-Humaam al-Hanafi (may Allaah have mercy on him) said:
They were unanimously agreed that the one who is defecating is not obliged to return the greeting at that moment or afterwards, because greeting him is haraam, unlike the one who is in the hamaam (i.e., bathing), if he is wearing a waist wrapper. End quote.
Fath al-Qadeer, 1/248
Al-Nawawi (may Allaah have mercy on him) said:
Our companions said: It is makrooh to greet him [meaning the one who is relieving himself], and if someone does greet him it does not deserve a response, because of the hadeeths of Ibn ‘Umar and al-Muhaajir. End quote.
It says in al-Mawsoo’ah al-Fiqhiyyah (34/11):
The Maalikis, Shafaa’is and Hanbalis are of the view that it is makrooh to greet with salaam one who is defecating. The Hanafis also regarded that as makrooh. Ibn ‘Aabideen said: What is meant by that also includes urinating. He said: And it seems that this means it is haraam. End quote.
Based on that: if a person enters a public washroom and does not find anyone doing wudoo' at the sinks, it is makrooh for him to say salaams to those who are in the stalls where people relieve themselves. But if he finds that some of them have finished relieving themselves and have started to do wudoo’ or to wash their hands in the places prepared for that, there is nothing wrong with saying salaam to these people and they must return the greeting.
And Allaah knows best.