Waves of different wavelengths refract differently because refraction depends on the change in speed of the wave as it passes from one medium to another. When a wave enters a different medium, such as going from air to water or from air to glass, its speed changes due to the change in the optical properties of the medium.
According to Snell's law, which describes the behavior of light when it crosses the boundary between two different media, the angle at which the wave is transmitted (refracted) is dependent on the ratio of the velocities (or speeds) of the wave in the two media and the angle at which the wave approaches the boundary.
The speed of a wave is directly related to its wavelength. When a wave enters a medium where its speed changes, the change in velocity affects the wave's direction, causing it to bend or refract. The degree of bending depends on the change in velocity, which in turn depends on the change in wavelength.
In general, when a wave moves from a medium with a lower refractive index to a medium with a higher refractive index (e.g., from air to water), its speed decreases and its wavelength shortens. Conversely, when a wave moves from a medium with a higher refractive index to a medium with a lower refractive index (e.g., from water to air), its speed increases and its wavelength lengthens.
As a result, waves of different wavelengths refract differently because they experience different changes in speed as they pass through different media, leading to variations in the angles at which they are bent. This phenomenon is commonly observed in optics, where different colors of light (each corresponding to a different wavelength) bend differently when passing through a prism, resulting in the dispersion of white light into its constituent colors.