Sahih al-Bukhari 5924
Narration text is preserved in its supplied Arabic and English. Translated interfaces and reading guides do not add narration translations in other languages.
لَوْ عَلِمْتُ أَنَّكَ تَنْظُرُ لَطَعَنْتُ بِهَا فِي عَيْنِكَ، إِنَّمَا جُعِلَ الإِذْنُ مِنْ قِبَلِ الأَبْصَارِ "
Narrated Sa`d:
A man peeped into the house of the Prophet (ﷺ) through a hole while the Prophet (ﷺ) was scratching his head with a Midrai (a certain kind of comb). On that the Prophet (ﷺ) said (to him), "If I had known you had been looking, then I would have pierced your eye with that instrument, because the asking of permission has been ordained so that one would not see things unlawfully."
Full reference and source
Sahih al-Bukhari 5924 In-book : Book 77, Hadith 139 USC-MSA web (English) : Vol. 7, Book 72, Hadith 807 (deprecated)
View source on Sunnah.com (opens in a new tab)