When the Prophet ﷺ was directed to face the Kaabah, the people asked, "Messenger of Allah, what about our brothers who died while praying toward Bayt al-Maqdis?"So Allah Almighty revealed, "And Allah would never let your faith go to waste" [Baqarah 2:143].
حدثنا هناد وأبو عمار قالا حدثنا وكيع عن إسرائيل عن سماك عن عكرمة
لما وجه النبي ﷺ إلى الكعبة قالوا يا رسول الله كيف بإخواننا الذين ماتوا وهم يصلون إلى بيت المقدس فأنزل الله تعالى {وما كان الله ليضيع إيمانكم} الآية
Sourcing, agreed upon by Bukhari and Muslim. Bukhari narrated it in the tafsir chapter, "the section on the words of Allah Most High, 'Indeed Safa and Marwa are among the rites of Allah,'" hadith 4496, from the narration of Sufyan Thawri. Muslim narrated it, hadith 1278, from the narration of Asim Ahwal, with the same wording.