Surah Al-Anaam(6), Verse 59:
وَعِندَهُ مَفَاتِحُ الْغَيْبِ لَا يَعْلَمُهَا إِلَّا هُوَ وَيَعْلَمُ مَا فِي الْبَرِّ وَالْبَحْرِ وَمَا تَسْقُطُ مِن وَرَقَةٍ إِلَّا يَعْلَمُهَا وَلَا حَبَّةٍ فِي ظُلُمَاتِ الْأَرْضِ وَلَا رَطْبٍ وَلَا يَابِسٍ إِلَّا فِي كِتَابٍ مُّبِينٍ
With Him are the keys of the unseen, the treasures that none knoweth but He. He knoweth whatever there is on the earth and in the sea. Not a leaf doth fall but with His knowledge: there is not a grain in the darkness (or depths) of the earth, nor anything fresh or dry (green or withered), but is (inscribed) in a record clear (to those who can read).
(English – Yusuf Ali)
(1) Ahadeeth which states it is taboo to urinate or defecate in the direction of Qibla
(a) It was narrated from Rafi’ bin Ishaq that he heard Abu Ayyub Al-Ansari say – when he was in Egypt: “By Allah, I do not know what I should do with these Karais (toilets). The Messenger of Allah (ﷺ) said: ‘When any one of you goes to defecate or urinate, let him not face toward the Qiblah, nor turn his back towards it.”
Sunan an-Nasa’i : Vol. 1, Book 1, Hadith 20
(b) Yahya related to me from Malik from Ishaq ibn Abdullah ibn Abi Talha that Rafiibn Ishaq, a mawla of the family of ash-Shifa who was known as the mawla of Abu Talha, heard Abu Ayyub al-Ansari, one of the companions of the Messenger of Allah (ﷺ) say, while he was in Egypt, “By Allah! I don’t know how to deal with these lavatories.” The Messenger of Allah (ﷺ) said, “When you go to defecate or urinate, do not expose your genitals towards the qibla, and do not put your back to it.”
Malik Muwatta : Book 14, Hadith 458
(2) Ahadeeth which states it is permissible to face towards or back to Qibla while defecation or urination
(a) Permissibility of facing towards Qibla
(i)Marwan al-Asfar said: I saw Ibn Umar make his camel kneel down facing the qiblah, then he sat down urinating in its direction. So I said: Abu AbdurRahman, has this not been forbidden? He replied: Why not, that was forbidden only in open country; but when there is something between you and the qiblah that conceals you , then there is no harm.
Sunan Abi Dawud 11
(ii)Narrated Jabir ibn Abdullah: The Prophet of Allah (ﷺ) forbade us to face the qiblah at the time of making water. Then I saw him facing it (qiblah) urinating or easing himself one year before his death.
Sunan Abi Dawud 13
(b) Permissibility of facing backwards to Qibla
Abdullah b. Umar said: I went up to the roof of the house of my sister Hafsa and saw the Messenger of Allah (ﷺ) relieving himself facing Syria. with his back to the Qibla.
Sahih Muslim 266b
(3)…the view of a number of scholars who sought to reconcile the evidence by interpreting the hadeeth of Abu Hurayrah and similar reports as referring to cases of relieving oneself out in the open without any screen, and the hadeeth of Jaabir ibn ‘Abd-Allaah and Ibn ‘Umar (may Allaah be pleased with them) as referring to cases when one is inside a building or there is a screen between oneself and the qiblah. From this it is known that it is permissible to face towards the qiblah or turn one’s back towards it when relieving oneself in any kind of building.
If the plans for the building have not yet been put into effect, and the toilets in the plan are facing towards the qiblah or have their backs towards it, then it is more on the safe side to alter them so that when relieving oneself one is not facing towards the qiblah or turning one’s back towards it, so as to avoid an area of scholarly dispute. But if they cannot be altered there is no sin involved because of the ahaadeeth quoted above. End quote.
Reference : Fataawa al-Lajnah al-Daa’imah, 5/97
*a part of information is taken from islamqa.info
ALLAH knows best