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.
bayhaqi:2192al-Barāʾ > Qīl Hadhā al--Adhīn Mātūā Qabl

[Machine] That they turn to the Kaaba and men were killed, so we did not know what to say about them. Then Allah revealed {And Allah would not let your faith be lost. Indeed Allah is Kind and Merciful to the people}. It was narrated by Al-Bukhari from Abu Nuaim.  

البيهقي:٢١٩٢وَبِإِسْنَادِهِ عَنِ الْبَرَاءِ قَالَ قِيلَ هَذَا الَّذِينَ مَاتُوا قَبْلَ

أَنْ تُحَوَّلَ إِلَى الْكَعْبَةِ وَرِجَالٌ قُتِلُوا فَلَمْ نَدْرِ مَا نَقُولُ فِيهِمْ فَأَنْزَلَ اللهُ ﷻ {وَمَا كَانَ اللهُ لِيُضِيعَ إِيمَانَكُمْ إِنَّ اللهَ بِالنَّاسِ لَرَءُوفٌ رَحِيمٌ} رَوَاهُمَا الْبُخَارِيُّ عَنْ أَبِي نُعَيْمٍ  


See similar narrations below:

Collected by Ṭabarānī
tabarani:11729ʿAbdullāh b. Muḥammad b. Saʿīd b. Abū Maryam > Muḥammad b. Yūsuf al-Firyābī > Isrāʾīl > Simāk b. Ḥarb > ʿIkrimah > Ibn ʿAbbās

[Machine] They said, "O Messenger of Allah, what do you think about those who died while they were praying towards Al-Masjid al-Aqsa? So Allah revealed, "Allah would not leave your faith to waste. Indeed, Allah is compassionate and merciful towards people."  

الطبراني:١١٧٢٩حَدَّثَنَا عَبْدُ اللهِ بْنُ مُحَمَّدِ بْنِ سَعِيدِ بْنِ أَبِي مَرْيَمَ ثنا مُحَمَّدُ بْنُ يُوسُفَ الْفِرْيَابِيُّ ثنا إِسْرَائِيلُ عَنْ سِمَاكِ بْنِ حَرْبٍ عَنْ عِكْرِمَةَ عَنِ ابْنِ عَبَّاسٍ قَالَ

قَالُوا يَا رَسُولَ اللهِ أَرَأَيْتَ الَّذِينَ مَاتُوا وَهُمْ يُصَلُّونَ إِلَى بَيْتِ الْمَقْدِسِ فَأَنْزَلَ اللهُ ﷻ {مَا كَانَ اللهُ لِيُضِيعَ إِيمَانَكُمْ إِنَّ اللهَ بِالنَّاسِ لرءُوفٌ رَحِيمٌ}