The Messenger of Allah ﷺ arrived in Medina and prayed facing Bayt al-Maqdis for sixteen months. Then he was directed to face the Kaabah. A man who had prayed with the Prophet ﷺ passed by a group from the Ansar and said, "I bear witness that the Messenger of Allah ﷺ has been directed to face the Kaabah." So they turned toward the Kaabah.
أخبرنا محمد بن إسمعيل بن إبراهيم قال حدثنا إسحق بن يوسف الأزرق عن زكريا بن أبي زائدة عن أبي إسحق
قدم رسول الله ﷺ المدينة فصلى نحو بيت المقدس ستة عشر شهرا ثم إنه وجه إلى الكعبة فمر رجل قد كان صلى مع النبي ﷺ على قوم من الأنصار فقال أشهد أن رسول الله ﷺ قد وجه إلى الكعبة فانحرفوا إلى الكعبة
Bukhari collected it in the Book of Faith, chapter "Prayer is part of faith," h: 399, 40, 4486, 4492, 7252, and Muslim in the Book of Mosques, chapter "The change of the qibla from Jerusalem to the Kaaba," h: 525, from the hadith of Abu Ishaq, with the same chain.