Sayyiduna Ibn Umar (may Allah be pleased with them both) narrates that I went to Sayyidah Hafsah bint Umar (may Allah be pleased with them both), so I climbed onto the roof of her house. I saw the Prophet (peace and blessings of Allah be upon him) with his back towards the Qiblah and his face towards Shaam, relieving himself. These are the words of Abdul A’la’s hadith, and in Abu Hisham’s narration (hadith) « مستقبل القبلة » the words are “facing the Qiblah.”
And the explanation of the evidence that the prohibition of facing or turning one's back to the Qiblah while defecating or urinating, as stated by the Prophet (peace be upon him), is regarding open fields and such places where there is no screen or barrier. As for toilets and those places where there is a wall or barrier between the person relieving himself and the Qiblah, there is concession in this matter.
Hadith Referenceصحيح ابن خزيمه / جماع أبواب الآداب المحتاج إليها في إتيان الغائط والبول إلى الفراغ منها / 59