Light does not actually accelerate when it transitions from a denser medium to a less dense medium. Instead, it undergoes a change in speed. The change in speed is caused by the interaction of light with the atoms or molecules of the medium it is passing through.
When light travels through a medium, it interacts with the electrons in the atoms or molecules of that medium. This interaction results in the absorption and re-emission of light by the electrons. The time it takes for this absorption and re-emission process to occur affects the overall speed of light in the medium.
In a denser medium, such as water, the atoms or molecules are more closely packed together, and the interactions between light and the electrons occur more frequently. As a result, the absorption and re-emission process slows down the speed of light.
When light enters a less dense medium, such as air, the atoms or molecules are further apart, and the interactions between light and the electrons are less frequent. Consequently, the absorption and re-emission process happens more quickly, allowing light to propagate at a faster speed.
It's important to note that although light changes speed when it moves from one medium to another, its frequency remains constant. This phenomenon is known as the principle of the constancy of the speed of light.