Abu Ayub reported,

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."

Tirmidhi 8

Sahih

حدثنا سعيد بن عبد الرحمن المخزومي حدثنا سفيان بن عيينة عن الزهري عن عطاء بن يزيد الليثي

عن أبي أيوب الأنصاري قال قال

رسول الله ﷺ إذا أتيتم الغائط فلا تستقبلوا القبلة بغائط ولا بول ولا تستدبروها ولكن شرقوا أو غربوا قال أبو أيوب فقدمنا الشام فوجدنا مراحيض قد بنيت مستقبل القبلة فننحرف عنها ونستغفر الله

الترمذي 8صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Purification
Chapter
Prohibition of facing the qibla when defecating or urinating
Numbering
Darussalam 8
Tirmidhi 8