It is narrated from Sayyiduna Jarir bin Abdullah (may Allah be pleased with him) that he asked the Noble Prophet (peace and blessings be upon him) about an accidental (sudden) glance, so the Prophet (peace and blessings be upon him) said: "Turn your gaze away."
Brief Explanation
(Commentary on Hadith 2678)
From this hadith, it is understood that if one’s gaze accidentally falls upon a non-mahram woman, there is no sin; however, it is obligatory to avert the gaze immediately at that moment.
Then, if one looks deliberately, he will be sinful.
In one hadith, it is stated that there is nothing (no sin) in the first glance, but it is not permissible to look a second time.
See Hadith (2744).