A man peeked through a hole in the door of the Messenger of Allah ﷺ, while the Messenger of Allah ﷺ had a comb with which he was scratching his head. When the Messenger of Allah ﷺ saw him, he said, "Had I known you were looking at me, I would have thrust this into your eye. Permission to enter was instituted only because of sight."
أخبرنا قتيبة قال حدثنا الليث عن ابن شهاب أن
أن رجلا اطلع من جحر في باب رسول الله ﷺ ومع رسول الله ﷺ مدرى يحك بها رأسه فلما رآه رسول الله ﷺ قال لو علمت أنك تنظرني لطعنت به في عينك إنما جعل الإذن من أجل البصر
Bukhari narrated it, Diyat, chapter "On one who peers into a people's house and they gouge out his eye, no diyah is owed for it," no. 6901, and Muslim, Adab, chapter "The prohibition of looking into another's house," no. 2156, from Qutayba, with the same wording. It is also in Kubra, no. 7064.