كتاب الطهارة
2  
The Book of Purification
(17)
Chapter: Cleaning oneself after relieving oneself
(17)
باب الاِسْتِطَابَةِ ‏‏
Sahih Muslim 264

Abu Ayyub reported:

The Apostle of Allah (ﷺ) 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.
وَحَدَّثَنَا زُهَيْرُ بْنُ حَرْبٍ، وَابْنُ، نُمَيْرٍ قَالاَ حَدَّثَنَا سُفْيَانُ بْنُ عُيَيْنَةَ، ح قَالَ وَحَدَّثَنَا يَحْيَى بْنُ يَحْيَى، - وَاللَّفْظُ لَهُ - قَالَ قُلْتُ لِسُفْيَانَ بْنِ عُيَيْنَةَ سَمِعْتَ الزُّهْرِيَّ، يَذْكُرُ عَنْ عَطَاءِ بْنِ يَزِيدَ اللَّيْثِيِّ، عَنْ أَبِي أَيُّوبَ، أَنَّ النَّبِيَّ صلى الله عليه وسلم قَالَ ‏ "‏ إِذَا أَتَيْتُمُ الْغَائِطَ فَلاَ تَسْتَقْبِلُوا الْقِبْلَةَ وَلاَ تَسْتَدْبِرُوهَا بِبَوْلٍ وَلاَ غَائِطٍ وَلَكِنْ شَرِّقُوا أَوْ غَرِّبُوا ‏"‏ ‏.‏ قَالَ أَبُو أَيُّوبَ فَقَدِمْنَا الشَّامَ فَوَجَدْنَا مَرَاحِيضَ قَدْ بُنِيَتْ قِبَلَ الْقِبْلَةِ فَنَنْحَرِفُ عَنْهَا وَنَسْتَغْفِرُ اللَّهَ قَالَ نَعَمْ ‏.‏
Reference : Sahih Muslim 264
In-book reference : Book 2, Hadith 76
USC-MSA web (English) reference : Book 2, Hadith 507
  (deprecated numbering scheme)