It has to do with melanin. Both skin and hair on people contain melanin. Since skin is “alive” and hair is “dead,” when the sun kills the melanin in the hair, the hair stays that color until new hair grows out. Since skin is alive, it responds to the sun damage and creates new melanin, so it looks darker.
Besides darkening skin, melanin also diffuses UV rays. Once the ultraviolet rays reach the melanin, they are spread out across the skin by melanin. This dispersal prevents the light from reaching our DNA. If ultraviolet light was able to reach our DNA without the protection of melanin, it would be corrupted and significantly reduce our life spans.
People with darker skin who produce melanin more often are able to scatter UV rays more efficiently when exposed to sun. Those with lighter skin are less adept at scattering rays, which raises the risk of skin cancer.
Tans disappear when melanin reaches the outermost layer of skin and is sloughed off in the natural skin shedding process. Since melanin is so close to the surface, it doesn’t take long for a tan to return to your natural skin color.