Sayyidina Abu Ayyub Ansari narrated that Allah's Messenger (SAW) said, "When you go to the toilet, do not face the qiblah while passing stool or urine nor turn your backs to it, but turn to the east or west."
Abu Ayyub (RA) said, "When we arrived in Syria, we found their privies built facing qiblah, so we would turn away from that and would seek Allah's forgiveness."