Ruling on facing towards the qiblah or turning one’s back towards it when relieving oneself in houses
Question

The Messenger of Allah (blessings and peace of Allah be upon him) said: “Do not face towards the qiblah when defecating or urinating; rather face towards the east or the west…” My question is: There are some toilets and washrooms in houses and apartments which face towards the qiblah; what is the ruling?
Praise be to Allah.The authentic hadiths which prohibit facing towards the qiblah or turning one’s back towards it when relieving oneself are numerous and indicate that it is prohibited to face towards th e qiblah or turn one’s back towards it when relieving oneself by urinating or defecating. When one is in the desert [or wilderness, or countryside], this is quite clear, and it is correct, because the hadiths clearly state that, so no one should ever face towards the qiblah or turn his back towards it when urinating or defecating in the wilderness, and it is not permissible to do so.
However, when it comes to relieving oneself inside buildings, the scholars differed more about that. Some of them said that it is permissible inside buildings, because it is soundly narrated from the Messenger (blessings and peace of Allah be upon him) that he relieved himself in Hafsah’s house facing in the direction of Syria and with his back towards the direction of the Ka`bah, as al-Bukhari and Muslim narrated in as-Sahihayn from Ibn `Umar (may Allah be pleased with him). They said: This indicates that there is nothing wrong with facing towards it or turning one’s back towards it inside the building, because the individual is concealed by the building, and the basic principle is that he may do that because of the indication that it is permissible and by way of emulating the Prophet (blessings and peace of Allah be upon him) in his actions. As he did that, it indicates that it is permissible, because he relieved himself squatting on two bricks, facing towards Syria and with his back facing the direction of the Ka`bah. This indicates that it is permissible to do that in buildings. Other scholars said that perhaps this applies only to the Prophet (blessings and peace of Allah be upon him), because he did that in a house and it did not become widely known, and he did not do it in the desert or wilderness. So this indicates that it applies only to him, and that the Muslims must not face towards the qiblah or turn their backs towards it even in buildings, acting in accordance with the hadiths which spoke of this issue in general terms without any exceptions. This view is stronger, which says that one should not face towards the qiblah or turn one’s back towards it at all, in buildings or in the wilderness.
But the idea that it is prohibited in buildings is subject to further discussion, because the basic principle is that the Prophet (blessings and peace of Allah be upon him) would not be exempted from this general ruling. But it is possible that this happened before doing that was prohibited, and it is possible that this exemption may be something that applies specifically to the Prophet (blessings and peace of Allah be upon him). Hence the prohibition on doing that in buildings is not like the prohibition on doing it in the wilderness. Therefore it is better for the believer not to face towards the qiblah or turn his back towards it when relieving himself, whether in the wilderness or in a building.
But in a building there is more lenience, especially if it is not easy to avoid that because there are many toilets that face towards the qiblah, so in that case a person is excused for two reasons:

Because there are toilets that face towards the qiblah and it is difficult to avoid them.
Because of what is known from the hadith of Ibn `Umar (may Allah be pleased with him) about the Prophet (blessings and peace of Allah be upon him) facing towards Syria and with his back towards the direction of the Ka`bah when he relieved himself in Hafsah’s house. This indicates that it is permissible, and according to the basic principle this does not apply specifically to him (blessings and peace of Allah be upon him) alone, so doing that is permissible, although it is better not to do that in buildings, but in the wilderness it is prohibited because there is nothing to exclude that from the general meaning of the hadith. This is the view that is most likely to be correct regarding this issue.

And Allah knows best.
Shaykh `Abd al-`Aziz ibn Baz (may Allah have mercy on him).
End quote from Fatawa Nur `ala ad-Darb, 2/574, 575).