While some people were offering Fajr prayer at Quba' (mosque), some-one came to them and said, "Tonight some Qur'anic Verses have been revealed to the Prophet ﷺ and he has been ordered to face the Kaʿba (at Mecca) (during prayers), so you too should turn your faces towards it." At that time their faces were towards Sham (Jerusalem) so they turned towards the Kaʿba (at Mecca).
بَيْنَا النَّاسُ بِقُبَاءٍ فِي صَلاَةِ الصُّبْحِ إِذْ جَاءَهُمْ آتٍ فَقَالَ إِنَّ النَّبِيَّ ﷺ قَدْ أُنْزِلَ عَلَيْهِ اللَّيْلَةَ قُرْآنٌ وَقَدْ أُمِرَ أَنْ يَسْتَقْبِلَ الْكَعْبَةَ فَاسْتَقْبِلُوهَا وَكَانَتْ وُجُوهُهُمْ إِلَى الشَّأْمِ فَاسْتَدَارُوا إِلَى الْكَعْبَةِ