Light refracts when it encounters glass in a lens primarily because it slows down, which causes it to bend.
When light travels from one medium to another (for example, from air to glass), it changes speed due to different optical densities. In glass, which is denser than air, light slows down, resulting in a change in direction—this bending of light is what we refer to as refraction.