It's because light of different wavelengths (-> different colours) are refracted with different strength by the atmosphere. Blue is refracted the most, thence it's the most spread out. When unusual amounts of refraction are going on, such as at sunset, the sky can turn red.