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)
بَيْنَمَا النَّاسُ بِقُبَاءَ فِي صَلَاةِ الصُّبْحِ إِذْ أَتَاهُمْ آتٍ فَقَالَ إِنَّ رَسُولَ اللهِ ﷺ قَدْ أُنْزِلَ عَلَيْهِ اللَّيْلَةَ قُرْآنٌ وَقَدْ أُمِرَ أَنْ يَسْتَقْبِلَ الْكَعْبَةَ فَاسْتَقْبِلُوهَا وَكَانَتْ وُجُوهُهُمْ إِلَى الشَّامِ فَاسْتَدَارُوا إِلَى الْكَعْبَةِ