Sayyiduna Sahl bin Sa’d (may Allah be pleased with him) narrates that a man peeped into one of the rooms of the Prophet (peace and blessings of Allah be upon him). The Prophet (peace and blessings of Allah be upon him) had a comb (made of wood with thorns) with which he was scratching his head. He said: If I had known that you were looking at me, I would have poked this comb into your eyes. The command to seek permission has been prescribed only because of the gaze.
Hadith Referenceالمنتقى ابن الجارود / كتاب الطلاق / 789