Language:
كتاب الصلاة
8  
Prayers (Salat)
(31)
Chapter: [During the obligatory Salat (prayers)] one should face the Qiblah (Kabah at Makkah) wherever one may be
(31)
باب التَّوَجُّهِ نَحْوَ الْقِبْلَةِ حَيْثُ كَانَ
Sahih al-Bukhari 399

Narrated Bara' bin `Azib:

Allah's Messenger (ﷺ) prayed facing Baitul-Maqdis for sixteen or seventeen months but he loved to face the Ka`ba (at Mecca) so Allah revealed: "Verily, We have seen the turning of your face to the heaven!" (2:144) So the Prophet (ﷺ) faced the Ka`ba and the fools amongst the people namely "the Jews" said, "What has turned them from their Qibla (Baitul-Maqdis) which they formerly observed"" (Allah revealed): "Say: 'To Allah belongs the East and the West. He guides whom he will to a straight path'." (2:142) A man prayed with the Prophet (facing the Ka`ba) and went out. He saw some of the Ansar praying the `Asr prayer with their faces towards Baitul-Maqdis, he said, "I bear witness that I prayed with Allah's Messenger (ﷺ) facing the Ka`ba." So all the people turned their faces towards the Ka`ba.

حَدَّثَنَا عَبْدُ اللَّهِ بْنُ رَجَاءٍ، قَالَ حَدَّثَنَا إِسْرَائِيلُ، عَنْ أَبِي إِسْحَاقَ، عَنِ الْبَرَاءِ بْنِ عَازِبٍ ـ رضى الله عنهما ـ قَالَ كَانَ رَسُولُ اللَّهِ صلى الله عليه وسلم صَلَّى نَحْوَ بَيْتِ الْمَقْدِسِ سِتَّةَ عَشَرَ أَوْ سَبْعَةَ عَشَرَ شَهْرًا، وَكَانَ رَسُولُ اللَّهِ صلى الله عليه وسلم يُحِبُّ أَنْ يُوَجَّهَ إِلَى الْكَعْبَةِ، فَأَنْزَلَ اللَّهُ ‏{‏قَدْ نَرَى تَقَلُّبَ وَجْهِكَ فِي السَّمَاءِ‏}‏ فَتَوَجَّهَ نَحْوَ الْكَعْبَةِ، وَقَالَ السُّفَهَاءُ مِنَ النَّاسِ ـ وَهُمُ الْيَهُودُ ـ مَا وَلاَّهُمْ عَنْ قِبْلَتِهِمُ الَّتِي كَانُوا عَلَيْهَا ‏{‏قُلْ لِلَّهِ الْمَشْرِقُ وَالْمَغْرِبُ يَهْدِي مَنْ يَشَاءُ إِلَى صِرَاطٍ مُسْتَقِيمٍ‏}‏ فَصَلَّى مَعَ النَّبِيِّ صلى الله عليه وسلم رَجُلٌ ثُمَّ خَرَجَ بَعْدَ مَا صَلَّى، فَمَرَّ عَلَى قَوْمٍ مِنَ الأَنْصَارِ فِي صَلاَةِ الْعَصْرِ نَحْوَ بَيْتِ الْمَقْدِسِ فَقَالَ هُوَ يَشْهَدُ أَنَّهُ صَلَّى مَعَ رَسُولِ اللَّهِ صلى الله عليه وسلم، وَأَنَّهُ تَوَجَّهَ نَحْوَ الْكَعْبَةِ‏.‏ فَتَحَرَّفَ الْقَوْمُ حَتَّى تَوَجَّهُوا نَحْوَ الْكَعْبَةِ‏.‏
Reference : Sahih al-Bukhari 399
In-book reference : Book 8, Hadith 50
USC-MSA web (English) reference : Vol. 1, Book 8, Hadith 392
  (deprecated numbering scheme)