Light waves are not always moving in a straight line. When it passes through a medium of a different refractive index, the waves will deviate. The phenomenon is called refraction and described according to Snell’s Law.
Earth’s atmosphere has variation in air density that depends on the altitude. As the refractive index changes with the density of the medium, light waves passing through Earth’s atmosphere also experience refraction.