Saying Bismillaah in one's heart when doing wudoo’ in the bathroom
It is makrooh to mention the name of Allaah in the place where one relieves oneself, out of respect for the name of Allaah so that His name will not be mentioned in a place of impurity which is the abode of the devils.
Al-Nawawi (may Allaah have mercy on him) said in al-Adhkaar (p. 21-22):
It is makrooh to recite dhikr and to speak when relieving oneself, whether that is in the desert or inside a building. All kinds of dhikr and speech are the same in this regard, except in cases of necessity. Some of our companions even say that if a person sneezes (in the bathroom), he should not say “al-hamdu Lillah”, and one should not say “yarhamuk-Allaah” to a person who sneezes, or return the greeting of salaam, or respond to the muezzin in the bathroom. All of that is makrooh but is not haraam. If a person sneezes and praises Allaah in his heart without moving his tongue, there is nothing wrong with that. The same applies when having intercourse
And we narrated that Ibn ‘Umar said: A man passed by the Prophet (peace and blessings of Allaah be upon him) whilst he was urinating and greeted him with salaam, but he did not return the greeting. (Narrated by Muslim in his Saheeh, 370). And it was narrated that al-Muhaajir ibn Qunfudh (may Allaah be pleased with him) said: I came to the Prophet (peace and blessings of Allaah be upon him) whilst he was urinating and greeted him with salaam, but he did not return the greeting until he had done wudoo’, then he apologized to me and said: I do not like to mention the name of Allaah unless I am in a state of purity.” (A saheeh hadeeth narrated by Abu Dawood, al-Nasaa’i and Ibn Maajah with a saheeh isnaad).
Based on this, if the place where you do wudoo’ is inside the bathroom – which is the place for relieving oneself and is not used for washing only – then it is makrooh to utter the name of Allaah in this place, even though it is prescribed to say Bismillaah (when doing wudoo’). Some of the scholars say that a person should say Bismillaah in his heart without uttering it on his tongue.
Shaykh Ibn ‘Uthaymeen (may Allaah have mercy on him) said in al-Sharh al-Mumti’ (1/130):
If a person is in the bathroom, then Imam Ahmad said: If a man sneezes he should praise Allaah in his heart. It may be deduced from this report that he should also say Bismillaah in his heart.
Others suggested that it is most likely that it is still prescribed to say Bismillaah. They said: He should say it out loud and it is not makrooh in this place.
Shaykh Ibn Baaz (may Allaah have mercy on him) said:
There is nothing wrong with doing wudoo’ inside the bathroom if necessary, and saying Bismillaah at the beginning, because saying Bismillaah is obligatory according to some scholars, and is strongly encouraged according to the majority. So he should do that, and the ruling on it being makrooh is waived, because such rulings are waived when it is necessary to say Bismillaah. A person is commanded to say Bismillaah when starting to do wudoo’, so he should say it and complete his wudoo’.
Majmoo’ Fataawa al-Shaykh Ibn Baaz, 10/28
It says in Fataawa al-Lajnah al-Daa’imah, 5/94
It is makrooh to utter the name of Allaah in the bathroom where a person relieves himself, out of respect for His name, but it is prescribed to say Bismillaah when starting to do wudoo’, because it is obligatory according to a group of scholars.
If the place where one does wudoo’ is outside the bathroom, even if it is attached to it, then it is prescribed for the person who is doing wudoo’ to utter Bismillaah and it is not makrooh in this case because he is not inside the bathroom.
And Allaah knows best.