I will hand wave how I understand what is mathematically shown here.
Classical electromagnetic radiation is composed of photons. Photons are not described by the Maxwell wave equations that describe light.
Photons are quantum mechanical particles, and are described by a wave function $Ψ$ which depends on the boundary condition problem on its mathematical form. In a medium this will be changing according to quantum mechanical scatterings of the photon with the various atoms of the medium, in this case a lattice since transparency is assumed.
The classical EM wave is a superposition/summation of zillion photon wavefunctions , and it is this total wavefunction that will give the $Ψ^*Ψ$ , the quantum mechanical description of the classical light wave.
Pictorially, one can think of the individual photons having longer tracks due to scatterings, so it takes them more time to get out of the medium. The confluence of photons still builds up the classical wave. Note that unless the medium changes the color of light, the photons do not lose appreciable energy/momentum ( within the heisenberg uncertainty), it is the change in their direction that makes the slowing of the EM light they build up, they still go with velocity c in the vacuum as, for the photons, most of the space is empty.
You ask:
This sounds as if light knows of the medium ahead of it. So, how is there no time at all needed for the refractions to occur as light enters the medium?
If the confluence of photons after their scattering with the lattice would not build again a light beam, it would mean that the medium is not transparent. It is the mathematical positioning of the lattice atoms that allows for photon scatterings so that the beam builds up in the medium, but just with a velocity different than c ( the photons always have c). In quantum mechanics the solution is whole in this case the scattering of zillions of photons on a lattice.
It is not the light that "knows" but it is the mathematics of photons scattering on a transparent lattice.