Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
quran:2:149

So from wherever you go out ˹for prayer, O Muhammad˺ turn your face toward al- Masjid al-Haram, and indeed, it is the truth from your Lord. And Allah is not unaware of what you do.  

From whatever place you issue, on a journey, turn your face towards the Sacred Mosque; it is the truth from your Lord. God is not heedless of what you do (ta‘malūna, ‘you do’, may also be read as ya‘malūna, ‘they do’, as already appears above ˹sc. 2:144˺; its repetition is intended to point out that the stipulation applies equally to being on a journey or otherwise).
القرآن:٢:١٤٩

وَمِنْ حَيْثُ خَرَجْتَ فَوَلِّ وَجْهَكَ شَطْرَ الْمَسْجِدِ الْحَرَامِ ۖ وَإِنَّهُ لَلْحَقُّ مِنْ رَبِّكَ ۗ وَمَا اللَّهُ بِغَافِلٍ عَمَّا تَعْمَلُونَ  

{ومن حيث خرجت} لسفر {فولِّ وجهك شطر المسجد الحرام وإنه للحق من ربك وما الله بغافل عما تعلمون} بالياء والتاء تقدم مثله وكرره لبيان تساوي حكم السفر وغيره.