The Messenger of Allah ﷺ forbade anyone going to relieve himself from facing the qiblah, and said, "Face east or west instead."
حدثنا أبو الطاهر أحمد بن عمرو بن السرح أنبأنا عبد الله بن وهب أخبرني يونس عن ابن شهاب عن عطاء بن يزيد أنه سمع
نهى رسول الله ﷺ أن يستقبل الذي يذهب إلى الغائط القبلة وقال شرقوا أو غربوا
Bukhari narrated it in the Book of Wudu, chapter "Do not face the qibla while urinating or defecating..." etc, hadith no. 144, and no. 394, and Muslim in the Book of Purification, chapter on istitabah (cleansing after relieving oneself), hadith no. 264, from the hadith of Zuhri through this chain.