While the people were offering the Fajr prayer at Quba' (near Medina), someone came to them and said: "It has been revealed to Messenger of Allah ﷺ tonight, and he has been ordered to pray facing the Kaʿba." So turn your faces to the Kaʿba. Those people were facing Sham (Jerusalem) so they turned their faces towards Kaʿba (at Mecca). (Using translation from Bukhārī 403)
إِنَّ رَسُولَ اللهِ ﷺ قَدْ أُنْزِلَ عَلَيْهِ اللَّيْلَةَ وَقَدْ أُمِرَ أَنْ يَسْتَقْبِلَ الْقِبْلَةَ فَاسْتَقْبِلُوهَا وَكَانَتْ وُجُوهُهُمْ إِلَى الشَّامِ فَاسْتَدَارُوا إِلَى الْكَعْبَةِ