Perhaps the questioner wants to know about the situations in which the obligation to face the qiblah whilst praying is waived, and it is valid to face a direction other than the qiblah.
One of the conditions of prayer being valid is facing the qiblah, and prayer is not valid without that, because Allaah has enjoined that repeatedly in the Qur’aan. Allaah says (interpretation of the meaning):
“so turn your face in the direction of Al-Masjid Al-Haraam (at Makkah). And wheresoever you people are, turn your faces (in prayer) in that direction”
When the Prophet (peace and blessings of Allaah be upon him) first came to Madeenah, he used to pray facing towards al-Bayt al-Maqdis (Jerusalem), with the Ka’bah behind him and Syria in front of him. But after that he hoped [?} that Allaah would change that, so he started lifting his face towards the heavens, looking for Jibreel to come down with the Revelation telling him to turn towards the Ka’bah, as Allaah says (interpretation of the meaning):
“Verily, We have seen the turning of your (Muhammad’s) face towards the heaven. Surely, We shall turn you to a Qiblah (prayer direction) that shall please you, so turn your face in the direction of Al-Masjid Al-Haraam (at Makkah)”[al-Baqarah 2:144]
So Allaah commanded him to turn towards al-Masjid al-Haraam, but there are three exceptions from that:
1 – If a person is unable to do that, such as one who is sick and is facing a direction other than the qiblah, and cannot turn to face it. The duty to face towards the qiblah is waived in this case, because Allaah says (interpretation of the meaning):
“So keep your duty to Allaah and fear Him as much as you can”
“Allaah burdens not a person beyond his scope”
And the Prophet (peace and blessings of Allaah be upon him) said: “If I command you to do a thing, then do as much of it as you can.” Narrated by al-Bukhaari, 7288; Muslim, 1337.
2 – If a person is a state of intense fear, such as one who is fleeing from an enemy or from a wild animal, or from a flood which may drown him. In that case he should pray no matter which direction he is facing. The evidence for that is the verse in which Allaah says (interpretation of the meaning):
“And if you fear (an enemy), perform Salaah (pray) on foot or riding. And when you are in safety, offer the Salaah (prayer) in the manner He has taught you, which you knew not (before)”
The phrase “if you fear” is general in meaning and includes all kinds of fear. And the phrase “And when you are in safety, offer the Salaah (prayer) in the manner He has taught you, which you knew not (before)” indicates that whatever part of the prayer a person omitted because of fear, there is no sin on him because of that – and that includes facing towards the qiblah.
This is also indicated by the two verses quoted above, and the hadeeth in which it says that obligations are connected to one’s ability to do them.
3 – When offering naafil (supererogatory) prayers when travelling, whether by plane, car or atop a camel; one may pray in whatever direction one is facing. This applies to naafil prayers such as Witr, night prayers (qiyaam), Duha and so on.
The traveller should offer all the naafil prayers exactly like one who is not travelling, except the regular Sunnah prayers such as the Sunnahs of Zuhr, Maghrib and ‘Isha’. The Sunnah is not to offer these prayers.
If a person wants to offer naafil prayers whilst travelling, he may offer them whatever direction he is facing. This is narrated in al-Saheehayn from the Messenger of Allaah (peace and blessings of Allaah be upon him).
In these three cases it is not obligatory to face towards the qiblah.
With regard to one who is ignorant, he has to face towards the qiblah, but if he tries to work it out then he finds out that he got it wrong, he does not have to repeat the prayer. We do not say that the obligation to face the qiblah is waived, rather he has to face the qiblah and he should try his best to do so. If he does his best then finds out that he got it wrong, he does not have to repeat his prayer. The evidence for that is the fact that the Sahaabah who were unaware that the qiblah had been changed to the Ka’bah were praying Fajr one day in the mosque of Quba’ when a man came to them and said: “Qur’aan has been revealed to the Messenger of Allaah (peace and blessings of Allaah be upon him) this night, and he has been commanded to face towards the Ka’bah, so turn to face it.” They were facing towards Syria and they turned to face towards the Ka’bah.
Narrated by al-Bukhaari, 304; Muslim, 526.
After the Ka’bah had been behind them, they put it in front of them, so they turned around but continued to pray. This happened at the time of the Messenger of Allaah (peace and blessings of Allaah be upon him), but he did not denounce it, so it is acceptable according to sharee’ah, i.e., if a person makes a mistake in the direction of the qiblah because he is unaware of it, he does not have to repeat the prayer, but if he comes to know of it, even during the prayer, then he has to turn to face the qiblah.
Facing towards the qiblah is one of the conditions of prayer without which the prayer is not valid, except in the three cases mentioned above, unless a person makes a mistake after doing his best to find out.
Majmoo’ Fataawa Ibn ‘Uthaymeen, 12/433-435
And Allaah knows best.