The Messenger of Allah ﷺ prayed facing Bayt al-Maqdis for sixteen or seventeen months, and the Messenger of Allah ﷺ wished to be turned toward the Kaabah. So Allah revealed, "We have certainly seen the turning of your face toward the heaven" [Baqarah 2:144], and he turned toward the Kaabah.The foolish among the people, namely the Jews, said, "What has turned them away from their qiblah which they used to face? Say, 'To Allah belong the east and the west. He guides whom He wills to a straight path.'" [Baqarah 2:142].A man prayed with the Prophet ﷺ, then after he had prayed he went out and passed by some people from the Ansar who were praying the afternoon prayer facing Bayt al-Maqdis. He said that he bore witness that he had prayed with the Messenger of Allah ﷺ and that the Prophet had turned toward the Kaabah. So the people shifted around until they were facing the Kaabah.
حدثنا عبد الله بن رجاء قال حدثنا إسرائيل عن أبي إسحاق
كان رسول الله ﷺ صلى نحو بيت المقدس ستة عشر أو سبعة عشر شهرا وكان رسول الله ﷺ يحب أن يوجه إلى الكعبة فأنزل الله {قد نرى تقلب وجهك في السماء} فتوجه نحو الكعبة وقال السفهاء من الناس وهم اليهود {ما ولاهم عن قبلتهم التي كانوا عليها قل لله المشرق والمغرب يهدي من يشاء إلى صراط مستقيم} فصلى مع النبي ﷺ رجل ثم خرج بعد ما صلى فمر على قوم من الأنصار في صلاة العصر نحو بيت المقدس فقال هو يشهد أنه صلى مع رسول الله ﷺ وأنه توجه نحو الكعبة فتحرف القوم حتى توجهوا نحو الكعبة