Hadithcore
Sahih Muslim, 265
sahih

Abu Huraira said:

When any one amongst you squats for answering the call of nature, he should neither turn his face towards the Qibla nor turn his back towards it.

وَحَدَّثَنَا أَحْمَدُ بْنُ الْحَسَنِ بْنِ خِرَاشٍ، حَدَّثَنَا عُمَرُ بْنُ عَبْدِ الْوَهَّابِ، حَدَّثَنَا يَزِيدُ، - يَعْنِي ابْنَ زُرَيْعٍ - حَدَّثَنَا رَوْحٌ، عَنْ سُهَيْلٍ، عَنِ الْقَعْقَاعِ، عَنْ أَبِي صَالِحٍ، عَنْ أَبِي هُرَيْرَةَ، عَنْ رَسُولِ اللَّهِ صلى الله عليه وسلم قَالَ ‏

‏ إِذَا جَلَسَ أَحَدُكُمْ عَلَى حَاجَتِهِ فَلاَ يَسْتَقْبِلِ الْقِبْلَةَ وَلاَ يَسْتَدْبِرْهَا ‏

‏ ‏.‏

References2 variants
In-Book Reference
Book 2, Hadith 77
USC-MSA web (English) reference
Book 2, Hadith 508 (deprecated numbering scheme)
Sharh · explanationclick to expand
The Prophet (ﷺ) taught his companions all the Islamic manners to the extent that he taught them the manners of entering the toilet. In this hadith, he forbade us to turn our faces or backs toward the prayer direction. This is out of glorifying and preserving the Kaaba, the Sacred House of Allah in Mecca. Instead, a Muslim has to avoid these two directions. In the two Sahihs, Abu Ayyoub Al-Ansary narrated that the Prophet said, “Turn toward the East or the West.” Finally, this hadith is one of the hadiths that clarifies the etiquette of relieving oneself..