Sahih al-Bukhari 40
Al-Barāʾ ibn ʿĀzib (r.a) narrated that the Prophet (saw), when he first came to Madīnah, stayed with his maternal relatives – or he [the narrator] said, ‘his maternal uncles’ – from the Anṣār, and that he offered his Prayers facing towards Jerusalem (Bait al-Maqdis) for 16 or 17 months, but he wished that his Qiblah would be towards the Kaʿbah, and the first Prayer which he offered [facing the Kaʿbah] was the ʿAṣr Prayer, and some people offered Prayer with him. Then, a man from among those who offered Prayer with him went out and passed by some people in a mosque who were in a state of rukūʿ. He said: ‘By Allāh, I testify that I prayed with the Messenger of Allāh (saw) facing Makkah.’ So they turned to face the Kaʿbah while remaining in the same position [of rukūʿ]. The Jews and the People of the Book [i.e. the Christians] were happy when he [the Prophet (saw)] would offer Prayer facing towards Jerusalem, but they disapproved when he turned his face towards the House [i.e. the Kaʿbah].
Zuhair said: ‘Abū Isḥāq narrated to us on authority of al-Barāʾ in this ḥadīth of his: “Some individuals had passed away or been slain before the Qiblah was altered, leaving us uncertain about how to address their circumstances. So Allāh the Exalted revealed: ‘And it does not behove Allāh to let your faith go in vain. (2:144)’.”’
Translation: Ahmadiyya Muslim Jamaat
Book 30: The (offering of) Salat (prayers) is a part of faith