Shaykh Ibn Uthaymeen was asked:
Oh Virtuous Shaikh: After this speech about giving greetings, we want to know the manner of giving greetings to the one who greets us when we are in the washroom. What do we do?
“The one who is in the washroom does not give greetings until he exits. However, if is obligated to respond, then there is no way [for him] to reply to the greetings. If he signals [to his companion] he cannot see him, and if he speaks, then it is necessary that he does not mention Allah in this place. Rather he waits until he exits. If his companion is still there, he returns the greeting to him, otherwise the reply drops from him [i.e. the obligation is removed from him]. This is because he was given greetings in a place where it is not allowed for him to return it”
[Liqaa ash-Shahri no. 13]
Faisal Ibn Abdul Qaadir Ibn Hassan