For the rebels, it's same reason they wear long trench coats and mostly black clothes. It's a stylistic choice, that both sells the rebels image, that they fly against convention, and the cyber punk look from futuristic stories like Blade Runner and Ghost in the Shell.
When Morpheus meets Neo, he is wearing sunglasses, despite being inside a house during a rainy night. It's just meant to look cool. They'll shed the shades and trench coats when they need to be more practical.
Trinity in particular also uses her sunglasses as eye protection when riding a motorcycle twice, both in the first and second movie.
For the agents, it's another deal altogether. They wear it as a disguise. An additional layer of impersonality. It's standard MIB fantasy clothing. A dark suit and shades.
To the best of my knowledge, the Wachowskis never commented on the shades in particular, but I'll leave here a nugget about shades:
Psychologist Paul Ekman, an authority on facial expressions, says that of the 23 facial expressions relating to human emotion, about one-third involve the eyes. Shades may slightly obscure your view of the world, but they also hide the world's view of how you are feeling.