While he was in Egypt, he said, "By Allah, I do not know what to do about these latrines," meaning the toilets, "for the Messenger of Allah ﷺ said, 'When one of you goes to relieve himself, whether to defecate or urinate, he should neither face the qiblah nor turn his back to it.'"
حدثنا إسحاق بن عيسى أخبرنا مالك عن إسحاق بن عبد الله عن رافع بن إسحاق مولى أبي طلحة أنه سمع
وهو بمصر والله ما أدري كيف أصنع بهذه الكرابيس يعني الكنف وقد قال رسول الله ﷺ إذا ذهب أحدكم إلى الغائط أو البول فلا يستقبل القبلة ولا يستدبرها
Its isnad is sahih. Ishaq bin Abdullah is Ibn Abu Talha, one of the well-known trustworthy narrators, and his hadith appears with the group of hadith compilers. Rafi bin Ishaq is also trustworthy, Tirmidhi graded his narration sahih, and Nasai transmitted from him.The hadith is found in Bukhari 1/245 number 144 in the chapter on wudu, Muslim 1/224 number 264, Malik 1/193 in the chapter on the qibla, Nasai 1/23 number 22, and Tabarani in Al-Kabir 4/141 number 3931.