After sixteen or seventeen months facing Jerusalem, the qiblah turns to the Ka‘bah.
For sixteen or seventeen months after his arrival in Madinah, the Prophet ﷺ prayed facing Bayt al-Maqdis while wishing to face the Ka‘bah. The first prayer he offered towards the Ka‘bah was ‘Asr, and the news spread to a mosque whose people turned while bowing (Sahih al-Bukhari 40). The command is in Qur’an 2:144. The people of Quba heard the next morning during Fajr and turned as well (Sahih al-Bukhari 403).
Masjid al-Qiblatayn, the “mosque of the two qiblahs”, is identified by historical tradition as the place where a congregation turned within one prayer.