The Messenger of Allah ﷺ said, "When you go to relieve yourselves, do not face the qiblah while urinating or defecating, nor turn your back to it. Rather, face east or west."Abu Ayub said, "When we came to Sham, we found that the latrines had been built facing the qiblah, so we would turn aside from it and seek Allah's forgiveness."
حدثنا سعيد بن عبد الرحمن المخزومي حدثنا سفيان بن عيينة عن الزهري عن عطاء بن يزيد الليثي
رسول الله ﷺ إذا أتيتم الغائط فلا تستقبلوا القبلة بغائط ولا بول ولا تستدبروها ولكن شرقوا أو غربوا قال أبو أيوب فقدمنا الشام فوجدنا مراحيض قد بنيت مستقبل القبلة فننحرف عنها ونستغفر الله
Agreed upon by Bukhari, Prayer, chapter on the direction faced by the people of Madinah, Syria, and the east, no. 394, and Muslim, Purification, cleaning oneself after relieving oneself, no. 264, from the hadith of Sufyan bin Uyayna, through him.There are also narrations on this subject from Abdullah bin Harith bin Juz Zubaydi [Ibn Majah, no. 317], Maqil [Abu Dawud, no. 10, and Ibn Majah, no. 319], Abu Umama [we did not find it], Abu Hurairah [Muslim, no. 265], and Sahl bin Hunayf [Ahmad, 3/487, and Darimi, nos. 670, 671].