Answered by Ustadh Salman Younas
Question: Recently, while I was praying salatul dhuhr I discovered that I was not facing qibla. When I remembered, I turned towards the qibla while I was still praying and continued the prayer to the end. Is my prayer valid or should I pray it again?
Answer: assalamu `alaykum
In this situation, you would have to restart your prayer.
If you realized while praying that you were not facing the Qibla, you would be allowed to turn towards the Qibla and continue your prayer if you were genuinely unsure about the direction of the Qibla before commencing prayer and you had (a) asked someone or consulted a source or (b) exercised your own independent judgment as to where the Qibla was in the absence of the aforementioned. [Mawsili, al-ikhtiyar]
Checked & Approved by Shaykh Faraz Rabbani.