Blue sky and red sunset come from the same beam of sunlight meeting the same atmosphere. What changes is geometry: when the Sun is high, light cuts through a relatively short column of air; when it sinks toward the horizon, the path length through the atmosphere expands dramatically.
In that shorter midday path, molecules of nitrogen and oxygen drive Rayleigh scattering, a process whose cross section scales inversely with the fourth power of wavelength. Shorter wavelengths near the blue end of the visible spectrum scatter far more efficiently into every direction, filling the dome of the sky with diffuse blue light while the direct Sun remains almost white to the eye.
As the Sun approaches the horizon, the same photons traverse a much longer optical path. Multiple scattering events and absorption by aerosols remove a large fraction of blue and green light from the direct beam. Longer wavelengths in the red and orange band survive this atmospheric filtering, so the disk of the Sun and nearby clouds take on warm hues while the overhead sky still carries the bluish signature of Rayleigh scattering.