كتاب الحج
15  
The Book of Pilgrimage
(68)
Chapter: It is recommended for pilgrims and others to enter the Ka'bah and pray therein, and supplicate in all its corners
(68)
باب اسْتِحْبَابِ دُخُولِ الْكَعْبَةِ لِلْحَاجِّ وَغَيْرِهِ وَالصَّلاَةِ فِيهَا وَالدُّعَاءِ فِي نَوَاحِيهَا كُلِّهَا
Sahih Muslim 1329 a

Ibn Umar (Allah be pleased with them) reported that Allah's Messenger (may peace, be upon him) entered the Ka'ba. Usama, Bilal and 'Uthman b. Talha, the keeper (of the Ka'ba), were along with him. He closed the door and stayed in it for some time. Ibn 'Umar (Allah be pleased with them) said:

I asked Bilal as he came out what Allah's Messenger (ﷺ) had done there. He said: He prayed there in (such a position) that two pillars were on his left side, one pillar on his right, and three pillars were behind him, and the House at that time was resting on six pillars.
حَدَّثَنَا يَحْيَى بْنُ يَحْيَى التَّمِيمِيُّ، قَالَ قَرَأْتُ عَلَى مَالِكٍ عَنْ نَافِعٍ، عَنِ ابْنِ عُمَرَ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم دَخَلَ الْكَعْبَةَ هُوَ وَأُسَامَةُ وَبِلاَلٌ وَعُثْمَانُ بْنُ طَلْحَةَ الْحَجَبِيُّ فَأَغْلَقَهَا عَلَيْهِ ثُمَّ مَكَثَ فِيهَا ‏.‏ قَالَ ابْنُ عُمَرَ فَسَأَلْتُ بِلاَلاً حِينَ خَرَجَ مَا صَنَعَ رَسُولُ اللَّهِ صلى الله عليه وسلم قَالَ جَعَلَ عَمُودَيْنِ عَنْ يَسَارِهِ وَعَمُودًا عَنْ يَمِينِهِ وَثَلاَثَةَ أَعْمِدَةٍ وَرَاءَهُ - وَكَانَ الْبَيْتُ يَوْمَئِذٍ عَلَى سِتَّةِ أَعْمِدَةٍ - ثُمَّ صَلَّى ‏.‏
Reference : Sahih Muslim 1329a
In-book reference : Book 15, Hadith 434
USC-MSA web (English) reference : Book 7, Hadith 3068
  (deprecated numbering scheme)