Why does the refraction of electromagnetic waves occur at the interface between two media?

Because the speed of propagation of electromagnetic waves in different environments is different.

Remember: The process of learning a person lasts a lifetime. The value of the same knowledge for different people may be different, it is determined by their individual characteristics and needs. Therefore, knowledge is always needed at any age and position.