Language:
كتاب الصلاة
8
Prayers (Salat)
(32)
Chapter: What has been said about (facing) the Qiblah (Kabah at Makkah) and wherever considered that there was no need to repeat the Salat (prayer) if someone offered prayers by mistake facing a direction other than that of the Qiblah
(32)
بَابُ مَا جَاءَ فِي الْقِبْلَةِ، وَمَنْ لاَ يَرَى الإِعَادَةَ عَلَى مَنْ سَهَا فَصَلَّى إِلَى غَيْرِ الْقِبْلَةِ
وَقَدْ سَلَّمَ النَّبِيُّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ فِي رَكْعَتَيِ الظُّهْرِ، وَأَقْبَلَ عَلَى النَّاسِ بِوَجْهِهِ، ثُمَّ أَتَمَّ مَا بَقِيَ.

Narrated `Umar (bin Al-Khattab):

My Lord agreed with me in three things: -1. I said, "O Allah's Messenger (ﷺ), I wish we took the station of Abraham as our praying place (for some of our prayers). So came the Divine Inspiration: And take you (people) the station of Abraham as a place of prayer (for some of your prayers e.g. two rak`at of Tawaf of Ka`ba)". (2.125) -2. And as regards the (verse of) the veiling of the women, I said, 'O Allah's Messenger (ﷺ)! I wish you ordered your wives to cover themselves from the men because good and bad ones talk to them.' So the verse of the veiling of the women was revealed. -3. Once the wives of the Prophet (ﷺ) made a united front against the Prophet (ﷺ) and I said to them, 'It may be if he (the Prophet) divorced you, (all) that his Lord (Allah) will give him instead of you wives better than you.' So this verse (the same as I had said) was revealed." (66.5).

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