To save ourselves from any harm, it is necessary that all those paths and ways are to be checked from where there is a possibility of any harm. Those rules and laws are indeed unsuccessful in which one path is checked very vigorously and the others are forgotten.
Islam does not give such baseless and weak laws. Thus, where it has given rules and guidelines to women about Hijab, at the same time, it has also instructed the men to guard their gaze in all places, whether they are passing through a market, going on the road or are present in any house. They are required to refrain from looking at those things which are prohibited, so that when it becomes necessary for women to leave their houses, they can do so without any fear and fulfill their needs and no blemish appears on their virtuousness and chastity. Allah Ta'ala says:
Ask the believers to keep their eyes always lowered and guard their private parts. That is purer for them. Surely Allah is Well Aware of the (works) which they are busy doing.
Translation: - Direct the believing men to keep their eyes always lowered and guard their private parts.
Surah Al Noor (24:30)
The mark of a Momin (believer) is that he keeps his gaze lowered. If he unintentionally ends up resting his gaze on a non-Mahram woman or something, which is forbidden by the Shariah, he immediately turns away his gaze. As given in the Hadith of Mo'jam Kabeer of Imam Tabarani:
It has been narrated on the authority of Hadhrat Jareer (May Allah Ta'ala be well pleased with him), he says: I asked the Holy Prophet (Sallallahu alaihi wa sallam) about gaze. He (Sallallahu alaihi wa sallam) said: When it falls on a non-Mahram, turn it away. (Mo'jam Kabeer, Hadith No. 2350)
It is given in another Hadith:
Translation of Hadith: I asked the Holy Prophet (Sallallahu alaihi wa sallam) about unintentionally seeing a non-Mahram. The Holy Prophet (Sallallahu alaihi wa sallam) said: Turn away your gaze. (Mo'jam Kabeer, Hadith No. 2351)