Language:
كتاب الأحكام
93  
Judgments (Ahkaam)
(19)
Chapter: Passing judgement in the mosque and ordering the punishment outside the Mosque
(19)
بَابُ مَنْ حَكَمَ فِي الْمَسْجِدِ حَتَّى إِذَا أَتَى عَلَى حَدٍّ أَمَرَ أَنْ يُخْرَجَ مِنَ الْمَسْجِدِ فَيُقَامَ
Sahih al-Bukhari 7167

Narrated Abu Huraira:

A man came to Allah's Messenger (ﷺ) while he was in the mosque, and called him, saying, "O Allah's Apostle! I have committed illegal sexual intercourse." The Prophet (ﷺ) turned his face to the other side, but when the man gave four witnesses against himself, the Prophet (ﷺ) said to him, "Are you mad?" The man said, "No." So the Prophet (ﷺ) said (to his companions), "Take him away and stone him to death. "

حَدَّثَنَا يَحْيَى بْنُ بُكَيْرٍ، حَدَّثَنِي اللَّيْثُ، عَنْ عُقَيْلٍ، عَنِ ابْنِ شِهَابٍ، عَنْ أَبِي سَلَمَةَ، وَسَعِيدِ بْنِ الْمُسَيَّبِ، عَنْ أَبِي هُرَيْرَةَ، قَالَ أَتَى رَجُلٌ رَسُولَ اللَّهِ صلى الله عليه وسلم وَهْوَ فِي الْمَسْجِدِ فَنَادَاهُ فَقَالَ يَا رَسُولَ اللَّهِ إِنِّي زَنَيْتُ‏.‏ فَأَعْرَضَ عَنْهُ‏.‏ فَلَمَّا شَهِدَ عَلَى نَفْسِهِ أَرْبَعًا قَالَ ‏"‏ أَبِكَ جُنُونٌ ‏"‏‏.‏ قَالَ لاَ‏.‏ قَالَ ‏"‏ اذْهَبُوا بِهِ فَارْجُمُوهُ ‏"‏‏.‏
Reference : Sahih al-Bukhari 7167
In-book reference : Book 93, Hadith 31
USC-MSA web (English) reference : Vol. 9, Book 89, Hadith 280
  (deprecated numbering scheme)