While some people were offering morning prayer at Quba' a man came to them and said, "A Qur'anic Order has been revealed to Messenger of Allah ﷺ tonight that he should face the Kaʿba at Mecca (in prayer), so you too should turn your faces towards it." At that moment their faces were towards Sham (i.e. Jerusalem) (and on hearing that) they turned towards the Kaʿba (at Mecca).
إِنَّ رَسُولَ اللَّهِ ﷺ قَدْ أُنْزِلَ عَلَيْهِ اللَّيْلَةَ قُرْآنٌ وَأُمِرَ أَنْ يَسْتَقْبِلَ الْكَعْبَةَ أَلاَ فَاسْتَقْبِلُوهَا وَكَانَ وَجْهُ النَّاسِ إِلَى الشَّأْمِ فَاسْتَدَارُوا بِوُجُوهِهِمْ إِلَى الْكَعْبَةِ