[Machine] The Prophet ﷺ was the first to arrive in Medina and stayed with his ancestors and extended family from the Ansar. He prayed facing the direction of Bait al-Maqdis (Jerusalem) for sixteen or seventeen months, and he preferred for his qibla (direction of prayer) to be towards the Kaaba. He also prayed the Asr prayer as the first prayer he offered in Medina, and some people prayed with him. A man who had prayed with him later passed by a group of people who were in the state of rukoo' (bowing) in prayer and said, "I bear witness by Allah that I have prayed with the Messenger of Allah ﷺ facing towards Makkah." They turned and faced the Kaaba in prayer. It pleased the Prophet ﷺ to have the qibla changed, and the Jews were amazed when he used to pray facing Bait al-Maqdis, just as the people of the Book were. However, when he turned his face towards the Kaaba they disapproved of it.
أَنَّ رَسُولَ اللهِ ﷺ كَانَ أَوَّلَ مَا قَدِمَ الْمَدِينَةَ نَزَلَ عَلَى أَجْدَادِهِ وَأَخْوَالِهِ مِنَ الْأَنْصَارِ وَأَنَّهُ صَلَّى قِبَلَ بَيْتِالْمَقْدِسِ سِتَّةَ عَشَرَ أَوْ سَبْعَةَ عَشَرَ شَهْرًا وَكَانَ يُعْجِبُهُ أَنْ تَكُونَ قِبْلَتُهُ قِبَلَ الْبَيْتِ وَأَنَّهُ صَلَّى أَوَّلَ صَلَاةٍ صَلَّاهَا صَلَاةَ الْعَصْرِ وَصَلَّى مَعَهُ قَوْمٌ فَخَرَجَ رَجُلٌ مِمَّنْ صَلَّى مَعَهُ فَمَرَّ عَلَى أَهْلِ مَسْجِدٍ وَهُمْ رَاكِعُونَ فَقَالَ أَشْهَدُ بِاللهِ لَقَدْ صَلَّيْتُ مَعَ رَسُولِ اللهِ ﷺ قِبَلَ مَكَّةَ قَالَ فَدَارُوا كَمَا هُمْ قِبَلَ الْبَيْتِ وَكَانَ يُعْجِبُهُ أَنْ يُحَوَّلَ قِبَلَ الْبَيْتِ وَكَانَ الْيَهُودُ قَدْ أَعْجَبَهُمْ إِذْ كَانَ يُصَلِّي قِبَلَ بَيْتِ الْمَقْدِسِ وَأَهْلُ الْكِتَابِ فَلَمَّا وَلَّى وَجْهَهُ قِبَلَ الْبَيْتِ أَنْكَرُوا ذَلِكَ