Anil S. answered 12/19/22
Ph.D. in Physics and fellowship in MRI Physics.
This phenomenon is based on the scattering of light by molecules in the air. The strength of scattering depends on the wavelength of light and the size of the molecule. When you look at the sky, the light scattered by molecules enters your eyes. The color blue is in larger proportions in sunlight. Thus, light with smaller wavelengths is scattered strongly based on Rayleigh's scattering formula. That reaches your eyes. This explains why it appears blue (due to its shorter wavelength).
At sunrise and sunset, the light travels a larger distance through the atmosphere. The blue and neighboring colors are scattered away in the path of travel and light reaching the observer is predominantly red.
I hope that answers your question.