Praise be to Allah.
Types of dhikr
There are two types of dhikr; 1- dhikr with the tongue such as reciting Quran and du`as, which is encouraged in the Shari`ah, and 2- dhikr in the heart, which means thinking of Allah and His greatness and power, or reciting the Quran in one’s heart. This does not bring the same reward as reading Quran, because the reward has to do with reading, which can only be done on the tongue (by moving the tongue and speaking the words). The same applies to du`a; they should be spoken on the tongue and it is not sufficient to recite it in the heart.
Can you say Allah in the bathroom?
The scholars differentiated between the two types of dhikr. They said that it is makruh to remember Allah on the tongue (by speaking) in the bathroom and glorify Allah in that place. With regard to remembering Allah in one's heart, they said that this is not makuh and there is nothing wrong with it.
The proof that this distinction is made between the two kinds of dhikr is the fact that the scholars agreed that it is permissible for a person who is in a state of impurity following sexual activity to recite Quran in his heart, but it is haram for him to recite it out loud or utter it.
“The scholars agreed that if a person who is junub thinks of Quran in his heart, without moving his tongue, he is not reciting it in the way that is forbidden for one who is junub.” (Sharh al-Nawawi ‘ala Sahih Muslim, 4/103)
Ibn al-Mundhir said in al-Awsat:
“`Ikrimah said: A person should not remember Allah on his tongue (by speaking) when he is in the toilet, rather (he should do so) in his heart.” (Al-Awsat, 1/341)
The Standing Committee said:
“It is part of Islamic etiquette that a person should remember his Lord when he wants to enter the toilet or the bathroom , by saying before he enters: “Allahumma inni a’udhu bika min al-khubthi wa’l-khabaith (O Allah, I seek refuge with You from the male and female devils).” But he should not mention Allah after he enters, rather he should stop mentioning Him after he enters.” (Fatawa al-Lajnah al-Daimah, 5/93)
Shaykh ‘Abd al-‘Aziz ibn Baz said:
“Remembering Allah in one's heart is permissible at all times and in all places, in the washroom and elsewhere. Rather what is makruh in the washroom and similar places is to remember Allah on one’s tongue (by speaking), except for saying Bismillah when beginning to do wudu . He should say that if it is not easy for him to do wudu outside the bathroom, because it is obligatory according to some of the scholars, and it is a confirmed Sunnah according to the majority.” (Fatawa al-Shaykh Ibn Baz, 5/408)
And Allah knows best.