Light travels at speed x through a vacuum, and then it encounters a physical medium and slows down, only to leave the physical medium and re-enter vacuum. The speed of light immediately re-accelerates to speed x, the speed before going through the physical medium. How does this happen, what is the cause of this?
When light travels through a physical medium the photons don't actually slow down. They still travel at the speed of light. What makes it look like it slows down is the interactions between the photons and the physical medium.
For example the electrons in atoms can absorb photons and go to a higher energy state and then re-emit the photons when they move back to their normal energy state.
How long it takes between the absorption and emission of the photons determines how fast the light moves through a medium.
But, if photons are absorbed an re-emitted, why do they (photons) have to get re-emitted on the same direction? Why not any direction?
If the photons really would get fully absorbed by the atoms then that is what one would expect. One would also expect that some photons would bump into more atoms and some into less and thus sometimes they would take a long time to go through the medium and sometimes they would go through in a pretty short time. However that is not what you actually measure, the photons always take the same amount of time to travel through the medium. The photons are actually not fully absorbed, one can think of them being "virtually absorbed". They follow every possible path and interact with all of the atoms. The paths that don't cancel out correspond to the most likely paths that the photon will travel on. If you mathematically add all of these waves together that are traveling at the speed of light you get a wave that is traveling slower.
When light goes through a transparent medium, the velocity decreases below c, giving an index of refraction:
The photons always travel with velocity c. Light emerges from a confluence of a large number of photons, in a quantum mechanical superposition of their wavefunctions.
The conundrum is solved because photons can scatter elastically with atoms and the lattice itself and, within the pulse that they build up as light, they travel longer paths than the classically defined optical light ray, which has the reduced velocity.
These individual photon scatters are virtual in the sense of Feynman diagrams, the real photons being the ones detected, by the eye or a detector. They are elastic because the color does not change in clear glass ( lets keep it simple)
Elastic scattering means that the phases are retained and thus images can be transmitted.
If the scattering is inelastic, the de-excitations of the excited atom or lattice will lose the phase relation of the photons and thus images will not be transmitted.
A quantum mechanical way of looking at it is that the system "photon +lattice" is analogous to the system "photon + double slit" : The individual photons travel a larger path , measured from the center between the slits to the point on the detector. In transparent media there is one quantum mechanical solution that keeps the phases between the individual photons that build up the emergent light.