While some people were at Quba (offering) morning prayer, a man came to them and said, "Last night Qur'anic Verses have been revealed whereby the Prophet ﷺ has been ordered to face the Kaʿba (at Mecca), so you too should face it." So they, keeping their postures, turned towards the Kaʿba. Formerly the people were facing Sham (Jerusalem) (Allah said):-- "And from whence-so-ever you start forth (for prayers), turn your face in the direction of the Sacred Mosque of Mecca (Al-Masjid-ul-Haram), and whence-so-ever you are, turn your face towards it (when you pray)" (2.150)
أَنْ يَسْتَقْبِلَ الْكَعْبَةَ فَاسْتَقْبِلُوهَا وَاسْتَدَارُوا كَهَيْئَتِهِمْ فَتَوَجَّهُوا إِلَى الْكَعْبَةِ وَكَانَ وَجْهُ النَّاسِ إِلَى الشَّأْمِ