why exactly does light bend in a medium??
There is this really nifty facility on the Internet called "Google Search". You would do well to learn how to use it. You can ask such questions directly and get good answers. When I Google that exact phrase, I got 20,000,000 hits and the ones on the first page of the search results were quite good.
I mean on an atomic scale what exactly happens?
There is no atomic scale. Photons are not atoms. It's more complicated than that. I suggest that you do some research on your own and come back if you have amore targeted question.
The short answer is that light has an energy that is the equivalent of mass and that "mass" is attracted by massive objects.
EDIT: OOPS ... I see that your original question wasn't why light bends around massive objects but why it bends when entering, say, glass. Google "diffraction".
Firstly I am speeaking about refraction not diffraction. And next I am asking what triggers the light to bend, there seems to be no exact answer to this. Like we can explain reflection by considering light as particles and elastic collisions , diffraction by considering light as waves etc.
Refraction is a consequence of light acting as a wave and waves bending as the phase velocity changes but the frequency doesn't when it crosses a boundary where the densities are different.
OOPS. My bad. I have very mild dyslexia and I make this kind of bone-headed word substitution sometimes. I once wrote a whole post here using the word proton when I meant photon. Folks thought I was nuts
See http://www.gcsescience.com/pwav42.htm It is about water waves but the same is true for light.
The parallel lines represent the wave-fronts (places of equal phase). The distance between them is equal to the wavelength. In the material of higher refractive index, the speed of the wave is less than in the low-index material. You see the wave-front changing shape and bend when it reaches the interface , as the part in the hight-index medium slows down.
It is an other question why is the speed of light less in a medium than in vacuum. You can explane it with the interaction of light with the atoms.
The complete answer in terms of quantum physics of materials is rather complex, and depends on the kind of material. You might get an idea of it from this FAQ post:
Separate names with a comma.