Sunlight turns the sky blue because shorter wavelengths scatter far more.
Air molecules deflect blue and violet light with intensity ∝ 1/λ⁴, sending it in every direction while longer red waves continue straight. That scattered light reaches us from all angles, so the daytime sky appears blue.
At sunset the Sun’s path through the atmosphere lengthens dramatically. Most short wavelengths scatter away before they arrive, leaving the surviving red and orange light to dominate what we see.
One simple inverse-fourth-power rule decides the colors overhead and on the horizon.