and: “The Messenger of Allah, peace and blessings be upon him, used to pray facing Jerusalem—while the Kaʿbah stood directly before him—until the verse was revealed: ﴿We have certainly seen the turning of your face toward the heaven, and We will surely turn you to a direction that pleases you. So turn your face toward the Sacred Mosque﴾ (al-Baqarah 2:144). When it was sent down, he turned to face the Kaʿbah.
While the people of Qubāʾ were performing the dawn prayer, a messenger arrived and announced, ‘Qur’an has been revealed to the Messenger of Allah, peace and blessings be upon him, during the night, and he has been commanded to face the Kaʿbah; so—listen—face it!’ Their faces had been toward Syria, so they all turned around, and their imam turned as well, leading them toward the new qiblah.” (1)
Al-Hafiz Ibn Kathir mentions the report in his Tafsir (1/159) and then remarks: “All of these chains are weak, yet they may reinforce one another. As for repeating the prayer when one later realizes he faced the wrong qibla, the scholars hold two opinions, and these traditions indicate that no make-up (qada) is required.”
I add: This is also the view of Ahmad and others, for al-Tirmidhi—after citing the hadith of Amir b. Rabiʿa—said: “Most scholars adopt this position. They say that if a person prays during cloudy weather in a direction other than the qibla, and afterward discovers the mistake, his prayer is still valid. This is the opinion of Sufyan al-Thawri, Ibn al-Mubarak, Ahmad, and Ishaq.” Their explicit statements are recorded in Masail al-Marwazi and in Masail ʿAbd Allah from his father.
I further note: This is the sound view in the Hanafi school as stated in al-Hidaya, in contrast to the Shafiʿis; for the preponderant opinion among them—according to al-Nawawi (3/255)—is that “the prayer must be repeated once the error is certain,” which is likewise implied by al-Shafiʿi in al-Umm (1/82).
The correct view is that of the first group, supported by the hadiths already cited and by the narration concerning the people of Qubaʾ, who were praying toward Bayt al-Maqdis (Jerusalem) and then turned toward the Kaʿba, as will soon be mentioned. Al-Sanʿani adopted the same conclusion (1/187).
(1) All of this is confirmed by sound hadiths.