All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His Slave and Messenger.
Undeniably, it is impermissible for a person to mention the Name of Allaah The Exalted or recite the Quran when relieving himself; out of reverence for the Name and Words of Allaah The Exalted; Allaah The Exalted Says (what means): {That [is so]. And whoever honors the symbols of Allaah – indeed, it is from the piety of hearts.} [Quran 22:32]
Al-Muhaajir ibn Qunfuth narrated: “I saw the Prophet, sallallaahu ‘alayhi wa sallam, while he was urinating, and saluted him. The Prophet, sallallaahu ‘alayhi wa sallam, did not reply until he performed ablution. He then apologized and said: “I disliked mentioning (the Name of) Allaah except in the state of purification.” [Ahmad, Abu Daawood, An-Nasaa’i, Ibn Maajah, An-Nawawi: Saheeh with a sound chain of narrators]
Al-Baghawi said:
If a person sneezes while relieving himself, he should praise Allaah in his heart. This is the opinion of Al-Hasan, Ash-Sha‘bi, An-Nakha‘i and Ibn Al-Mubaarak .
However, Muslim scholars hold different opinions regarding reciting the Quran or mentioning the name of Allaah The Exalted in the bathroom and whether it is forbidden or merely disliked. Apparently, it is prohibited, for it contradicts the reverence that is due to Allaah,The Exalted, His Names, Attributes, and Words.
However, there is no blame upon the person who recites the Quran or mentions the Name of Allaah The Exalted unintentionally in the bathroom, although he should train himself to remain silent when relieving himself by reminding himself that it is not a proper place for the mention of Allaah The Exalted. Furthermore, you may chew gum or the like to keep your mouth busy while relieving yourself. In fact, it was reported that one of our righteous predecessors used to put a stone in his mouth while relieving himself so as to refrain from mentioning the Name of Allaah The Exalted in the bathroom or engaging in useless chatter.
Allaah Knows best.