Hair may look darker when wet for several reasons. First is its proximity to water, altering how light reflects off it; secondly is any dye applied for coloring it; finally strands may become denser with moisture making the overall effect darker than expected.
Though many are surprised by this phenomenon, it's actually nothing to do with hair changing colors - rather it has everything to do with how light interacts with its surface. When wet hair hits light sources, less of it reflects back into the eye - giving an appearance of darker locks than when they're dry.
To understand why this occurs, it may help to think of hair like a mirror: when light hits it, it bounces off of its reflective surface and onto your eye. Wet hair tends to stick together more, creating an extremely thin film over all strands - reflecting less photons of light back onto its surface compared to dry conditions and making the color seem darker than it would when dry.
Color in fabric or hair is determined by how it scatters light. Rough, granular materials like rock or cloth appear lighter as their irregularities cause light to hit them from multiple directions and scatter off into different directions, while smooth surfaces have less irregularities so more of the light that hits them gets absorbed by their surfaces - this explains why damp hair appears darker due to being similar to rough granular materials than smooth ones; wetness brings out this characteristic even further in its own hair texture compared to dry locks.
Naturally dark hair provides some protection from the sun's ultraviolet rays, particularly if long enough to cover facial features, ears, neck and scalp. People with light-colored or blond hair should take extra precaution when spending time in direct sunlight as this puts them at greater risk of sun damage and skin cancer due to not providing as much shade protection.
Maintaining clean hair can help to preserve both its skin and health, including its color. Regularly shampooing with quality shampoo and conditioning it regularly is key in this regard; to do so properly it is also important to limit styling products or dye usage, using sulfate-free shampoo if you do dye it, as well as investing in water filters and shower heads that reduce hard minerals or chlorine in water, which could further help your hair appear radiantly healthy.