Why is it that the frequency of light ray does not get altered when it travels from rarer to denser medium even if the wavelength and speed do?
All waves are created by something undergoing regularly repeating vibrations. In the case of light, this is most commonly accomplished by the vibration of electrons either in a electromagnetic field, or as the oscilate (vibrate) between energy levels of atomic orbitals.
The vibrations of the object creating the wave is what creates the frequency of the wave. The wavelength and speed are then determined by the medium through which the wave travels. Once the wave is created by the vibration, the frequency is generally fixed.
The relationship between frequency, wavelength, and wave speed is
V = FW. So, if F is kept fixed, as the wave moves into a more optically dense material, the speed will slow down and the wavelength will need to decrease in order to keep F constant.