Praise be to Allah.
Ruling on looking at women
Looking at (non-mahram) women is haram because Allah has commanded the believers to lower their gaze. Allah says (interpretation of the meaning):
“Tell the believing men to lower their gaze (from looking at forbidden things), and protect their private parts (from illegal sexual acts).” [al-Nur 24:30]
This was also enjoined by His Messenger (peace and blessings of Allah be upon him). It was narrated that Jarir said: I asked the Messenger of Allah (peace and blessings of Allah be upon him) about a sudden accidental glance. He said, “Avert your gaze .” (Narrated by Abu Dawud, al-Nikah, 1836; classed as sahih by al-Albani in Sahih Abi Dawud, no. 1880)
Hence it is obligatory to follow the command of Allah and His Messenger. Allah says (interpretation of the meaning):
“And let those who oppose the Messenger’s (Muhammad’s) commandment (i.e. his Sunnah legal ways, orders, acts of worship, statements) (among the sects) beware, lest some Fitnah (disbelief, trials, afflictions, earthquakes, killing, overpowered by a tyrant) should befall them or a painful torment be inflicted on them.” [al-Nur 34:63]
Does looking at women invalidate the fast?
With regard to effect of looking at non-mahram women on one's fast, the Standing Committee was asked about this and they replied: It does not invalidate the fast, but he must lower his gaze . (Fatawa al-Lajnah al-Daimah li’l-Ifta, 10/274)
So the Muslim, especially one who is fasting, must avert his gaze from them (non-mahram women) so that his fasting will not be undermined by haram things. Whoever does such a thing must repent to Allah.
And Allah knows best.