عن عبد الله بن عمر رضي الله عنهما قال: ((رَقيت يومًا على بيت حفصة، فرَأَيتُ النبيَّ -صلَّى الله عليه وسلَّم-يَقضِي حاجته مُسْتَقبِل الشام، مُسْتَدبِر الكعبة)).
وفي رواية:((مُسْتَقبِلا بَيتَ المَقدِس)) . [صحيح] - [متفق عليه] المزيــد ...
‘Abdullāh ibn ‘Umar (may Allah be pleased with him) reported: One day I climbed over Hafsah's house, and I saw the Prophet (may Allah's peace and blessings be upon him) relieving himself while facing the Levant, with his back toward the Ka‘bah.
In another version, he said:"while facing Bait al-Maqdis." Sahih/Authentic. - [Al-Bukhari and Muslim]
Ibn ‘Umar (may Allah be pleased with him) mentions that one day he went to the house of his sister Hafsah, the Prophet's wife. He went up on the roof of her house and saw the Prophet (may Allah's peace and blessings be upon him) answering the call of nature while facing the direction of the Levant and his back was toward the Qiblah. Ibn ‘Umar (may Allah be pleased with them) said this in response to those who said that one should not face the direction of Jerusalem, while answering the call of nature, and that is why the author mentioned the other version which adds:"...facing Bait al-Maqdis." So, if someone faces the Qiblah while praying within a building, there is nothing wrong with that.