Abu Ayub reported,

The Prophet ﷺ said, "When you go to relieve yourselves, do not face the qiblah, nor turn your backs 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 and ask Allah the Exalted for forgiveness."Zuhri reported from Ata, who said, "I heard Abu Ayub narrate the same from the Prophet ﷺ."

Bukhari 394

Sahih

حدثنا علي بن عبد الله قال حدثنا سفيان قال حدثنا الزهري عن عطاء بن يزيد الليثي

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

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

البخاري 394صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Prayer
Chapter
Qiblah of the people of Madinah, the people of Sham, and the people of the east
Numbering
Darussalam 394
Bukhari 394