Narrated Abu Aiyub Al-Ansari:
Allah’s Messenger (ﷺ) said, “If anyone of you goes to an open space for answering the call of nature he should neither face nor turn his back towards the Qibla; he should either face the east or the west.
Narrated Abu Aiyub Al-Ansari: The Prophet said, “While defecating, neither face nor turn your back to the Qibla but face either east or west.” Abu Aiyub added. “When we arrived in Sham we came across some lavatories facing the Qibla; therefore we turned ourselves while using them and asked for Allah’s forgiveness.”
Sahih Bukhari 1:8:388
Abu Ayyub reported: The Apostle of Allah (may peace be upon him) said: Whenever you go to the desert, neither turn your face nor turn your back towards the Qibla while answering the call of nature, but face towards the east or the west. Abu Ayyub said: When we came to Syria we found that the latrines already built there were facing towards the Qibla. We turned our faces away from them and begged forgiveness of the Lord. He said: Yes.
Sahih Muslim 2:507