When the Messenger of Allah ﷺ arrived in Madinah, he prayed facing Bayt al-Maqdis for sixteen or seventeen months. The Messenger of Allah ﷺ wished to be directed toward the Kaabah, so Allah revealed, "We have certainly seen the turning of your face toward the heaven, so We will surely turn you to a qiblah with which you will be pleased. So turn your face toward al-Masjid al-Haram" [Baqarah 2:144]. He was then turned toward the Kaabah, which he loved.A man prayed the afternoon prayer with him, then passed by some people from the Ansar who were in the bowing position during the afternoon prayer, facing Bayt al-Maqdis. He told them that he bore witness that he had prayed with the Messenger of Allah ﷺ and that he had been directed toward the Kaabah. So they turned while still bowing.
حدثنا هناد حدثنا وكيع عن إسرائيل عن أبي إسحق
لما قدم رسول الله ﷺ المدينة صلى نحو بيت المقدس ستة أو سبعة عشر شهرا وكان رسول الله ﷺ يحب أن يوجه إلى الكعبة فأنزل الله {قد نرى تقلب وجهك في السماء فلنولينك قبلة ترضاها فول وجهك شطر المسجد الحرام} فوجه نحو الكعبة وكان يحب ذلك فصلى رجل معه العصر قال ثم مر على قوم من الأنصار وهم ركوع في صلاة العصر نحو بيت المقدس فقال هو يشهد أنه صلى مع رسول الله ﷺ وأنه قد وجه إلى الكعبة قال فانحرفوا وهم ركوع
[Hasan] Abu Dawud also narrated it in the Book of Sunnah, chapter on the evidence that faith increases and decreases, hadith no. 4680, from the hadith of Simak, with this wording. Hakim graded it sahih at 2/269, as did Dhahabi at 2/269, but its chain of transmission is daif. The hadith has corroborating narrations in Bukhari (4486) and elsewhere.