Bara bin Azib reported,

When the Prophet ﷺ first arrived in Medina, he stayed with his grandfathers, or he said his maternal uncles, from the Ansar. He prayed facing Jerusalem for sixteen or seventeen months, but he wished that his prayer direction would be toward the Kabah.The first prayer he performed facing the Kabah was the afternoon prayer, and a group of people prayed with him. One of those who had prayed with him went out and passed by the people of a mosque while they were bowing in prayer. He said, "I swear by Allah, I have just prayed with the Messenger of Allah ﷺ facing Mecca." So they turned, just as they were, to face the Kabah.The Jews and the People of the Book had been pleased when he was praying toward Jerusalem, but when he turned his face toward the Kabah, they rejected this.Zuhayr said, Abu Ishaq narrated to us from al-Bara in this hadith of his that some men had died upon the previous prayer direction before it was changed, and others had been killed, and we did not know what to say about them. Then Allah Most High revealed, "And Allah would never let your faith go to waste" [Baqarah 2:143].

Bukhari 40

Sahih

حدثنا عمرو بن خالد قال حدثنا زهير قال حدثنا أبو إسحاق

عن البراء بن عازب

أن النبي ﷺ كان أول ما قدم المدينة نزل على أجداده أو قال أخواله من الأنصار وأنه صلى قبل بيت المقدس ستة عشر شهرا أو سبعة عشر شهرا وكان يعجبه أن تكون قبلته قبل البيت وأنه صلى أول صلاة صلاها صلاة العصر وصلى معه قوم فخرج رجل ممن صلى معه فمر على أهل مسجد وهم راكعون فقال أشهد بالله لقد صليت مع رسول الله ﷺ قبل مكة فداروا كما هم قبل البيت وكانت اليهود قد أعجبهم إذ كان يصلي قبل بيت المقدس وأهل الكتاب فلما ولى وجهه قبل البيت أنكروا ذلك قال زهير حدثنا أبو إسحاق عن البراء في حديثه هذا أنه مات على القبلة قبل أن تحول رجال وقتلوا فلم ندر ما نقول فيهم فأنزل الله تعالى {وما كان الله ليضيع إيمانكم}

البخاري 40صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Faith
Chapter
Prayer is part of faith
Numbering
Darussalam 40
Bukhari 40