Sayyiduna Abu Ayyub Ansari (may Allah be pleased with him) narrates: The Noble Prophet (peace and blessings be upon him) said: "When any person goes to relieve himself, he should neither face the Qiblah nor turn his back towards it while defecating or urinating, but (from the perspective of Madinah) he should face towards the east or the west." Sayyiduna Abu Ayyub Ansari (may Allah be pleased with him) narrates: When we came to Syria, we found toilets built facing the direction of the Qiblah, so we would turn slightly while sitting in them and would seek forgiveness from Allah Almighty.
Hadith Referenceصحیح ابن حبان / كتاب الطهارة / 1416
Hadith Gradingفضيلة الشيخ الإمام محمد ناصر الدين الألبانيصحيح.فضيلة الشيخ العلّامة شُعيب الأرناؤوطحديث صحيح، ابن أبي السري: هو محمد بن المتوكل - وإن كان كثير الأوهام - قد توبع عليه، وباقي رجاله ثقات رجال الشيخين.