It is easy to explain in clssical wave mechanics, although brevity prevents me from doing it here. Look for any good electromagnetics text, and find the chapter on plane waves in dielectric and conducting media. The upshot is that the wave propagation speed is v = 1/square root(ue), where u is the permeability of the space, and e is the permittivity.

In glass, the permittivity is greater than in vacuum, so the wave velocity decreases.

In free space, u and e obtain their smallest values, and v=c.

In QM, the photon in question still maintains its wave functions. Since the waves slow down, the photonic "energy packet" also slows down.