It is narrated from Sayyiduna Abdullah bin Umar (may Allah be pleased with them both): Indeed, people say that at the time of relieving oneself, do not face the Qiblah or Bayt al-Maqdis. And Abdullah (may Allah be pleased with him) says: I once climbed onto the roof of my house and saw the Messenger of Allah (peace and blessings be upon him) sitting on two bricks (relieving himself), and his face was towards Bayt al-Maqdis (that is, his back was towards the Ka'bah). Ibn Umar (may Allah be pleased with them both) said to his student Wasi' (may Allah have mercy on him): Perhaps you are among those people who pray on their buttocks? Wasi' (may Allah have mercy on him) says: I said, "By Allah, I do not know what you mean?" (Imam Malik, may Allah have mercy on him, says: Abdullah bin Umar (may Allah be pleased with them both) meant by this the person who does not rise from the ground in prayer and clings to the ground in prostration, which is an incorrect and contrary-to-Sunnah act). Abu Ja'far (may Allah have mercy on him) says: I heard Muzani (may Allah have mercy on him) saying: Imam Shafi'i (may Allah have mercy on him) says: According to us, there is no contradiction between the hadith of Sayyiduna Abdullah bin Umar (may Allah be pleased with them both) and the hadith of Abu Ayyub Ansari (may Allah be pleased with him). In open spaces, facing or turning one's back (to the Qiblah) is disliked, because there is no hardship in acting upon this hadith in the desert, so there is no concession. And in houses, in latrines, one will act as is possible. The Imam (may Allah have mercy on him) says: I have explained this hadith in detail elsewhere.
Hadith Referenceالسنن المأثورة / باب ما جاء في الصلاة على الراحلة / 113
Hadith Takhrijصحیح بخاری، الوضوء، باب من تبرز علی لبنتین، رقم : 145، صحیح مسلم ،الطهارة، باب الاستطابة، رقم : 266۔