كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
5  
The Book of Mosques and Places of Prayer
(2)
Chapter: Changing the qiblah from Al-Quds (Jerusalem) to the Ka`bah
(2)
باب تَحْوِيلِ الْقِبْلَةِ مِنَ الْقُدْسِ إِلَى الْكَعْبَةِ ‏
Sahih Muslim 525 a

Al-Bara' b. 'Azib reported:

I said prayer with the Apostle (ﷺ) turning towards Bait-ul-Maqdis for sixteen months till this verse of Surah Baqara wis revealed:" And wherever you are turn your faces towards it" (ii. 144). This verse was revealed when the Apostle (ﷺ) had said prayer. A person amongst his people passed by the people of Ansar as they were engaged in prayer. He narrated to them (this command of Allah) and they turned their faces towards the Ka'ba.
حَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا أَبُو الأَحْوَصِ، عَنْ أَبِي إِسْحَاقَ، عَنِ الْبَرَاءِ بْنِ عَازِبٍ، قَالَ صَلَّيْتُ مَعَ النَّبِيِّ صلى الله عليه وسلم إِلَى بَيْتِ الْمَقْدِسِ سِتَّةَ عَشَرَ شَهْرًا حَتَّى نَزَلَتِ الآيَةُ الَّتِي فِي الْبَقَرَةِ ‏{‏ وَحَيْثُمَا كُنْتُمْ فَوَلُّوا وُجُوهَكُمْ شَطْرَهُ‏}‏ فَنَزَلَتْ بَعْدَ مَا صَلَّى النَّبِيُّ صلى الله عليه وسلم فَانْطَلَقَ رَجُلٌ مِنَ الْقَوْمِ فَمَرَّ بِنَاسٍ مِنَ الأَنْصَارِ وَهُمْ يُصَلُّونَ فَحَدَّثَهُمْ فَوَلَّوْا وُجُوهَهُمْ قِبَلَ الْبَيْتِ ‏.‏
Reference : Sahih Muslim 525a
In-book reference : Book 5, Hadith 16
USC-MSA web (English) reference : Book 4, Hadith 1071
  (deprecated numbering scheme)