Imagine a world with only brunettes in it. That was the world when the first human ancestors first started to appear as primates adapted and speciation created the lineage that would eventually lead to our modern-day humans. It is believed the very first hominids lived on the continent of Africa. Since Africa is directly on the equator, sunlight shines directly down throughout the entire year. This impacted evolution as it drove the natural selection of pigments in humans as dark as possible. Dark pigments, like melanin, help block harmful ultraviolet rays from penetrating into the body through the skin and hair. The darker the skin or hair, the more protected from the sunlight the individual is.
Once these human ancestors started migrating to other places throughout the world, the pressure to select for skin and hair colors as dark as possible let up and lighter skin colors and hair colors became much more common. In fact, once the human ancestors reached latitudes as high north as what is known today as the Western European and Nordic countries, skin color had to be much lighter in order for the individuals living there to get enough Vitamin D from the sunlight. While darker pigmentation in skin and hair block unwanted and harmful ultraviolet rays from the sun, it also blocks other components of sunlight that are necessary for survival. With as much direct sunlight as countries along the equator get on a daily basis, capturing Vitamin D is not an issue. However, as human ancestors migrated farther north (or south) of the equator, the amount of daylight varied throughout the year. In the winter, there were very few daylight hours in which the individuals could get out and obtain the necessary nutrients. Not to mention it was also cold during these times which made it even more unappealing to get out during the daylight at all.
As these populations of migrating human ancestors settled in these colder climates, pigments in the skin and hair started to fade and give way to new color combinations. Since hair color is polygenic, many genes control the actual phenotype of hair color in humans. That is why there are so many different shades of colors seen in different populations throughout the world. While it is possible that skin color and hair color are at least somewhat linked, they are not so closely linked that various combinations are not possible. Once these new shades and colors emerged in various areas around the world, it started to be less of a natural selection of traits than a sexual selection.
Studies have been done to show that the less abundant any given hair color is in the gene pool, the more attractive they tend to be for suitors. This is thought to have led to the proliferation of blonde hair in Nordic areas, which favored as little pigment as possible for maximum absorption of Vitamin D. Once blonde hair began to be seen on individuals in the area, their mates found them more attractive than the others who had dark hair. Over several generations, blonde hair became much more prominent and proliferated over time. The blonde Nordics continued to migrate and found mates in other areas and hair colors blended.
Red hair is most likely the result of a DNA mutation somewhere along the line. Neanderthals also most likely had lighter hair colors than those of their Homo sapien relatives. There was thought to be some gene flow and cross-breeding of the two different species in the European areas. This probably led to even more shades of the different hair colors.