The Prophet ﷺ said, "Do not face the qiblah nor turn your back to it when relieving yourselves, whether for defecation or urination. Rather, face east or west."
أخبرنا محمد بن منصور قال حدثنا سفيان عن الزهري عن عطاء بن يزيد
أن النبي ﷺ قال لا تستقبلوا القبلة ولا تستدبروها لغائط أو بول ولكن شرقوا أو غربوا
[Agreed upon. Bukhari narrated it in the Book of Prayer, Chapter on the direction of prayer for the people of Madinah, Syria, and the East, hadith (394), and Muslim in the Book of Purification, Chapter on cleaning oneself after relieving oneself, hadith (264), from the hadith of Sufyan bin Uyayna with this wording. It is also in Kubra, hadith (20