When you are out and about getting exposed to sunlight, the pituitary gland produces a hormone called the Melanocyte-stimulating hormone (MSH). This hormone stimulates your body into producing melanin, the cause of darker skin colors and tanning.
The production of MSH is tied to the optic nerve. When the optic nerve receives a certain amount of sunlight, it'll tell the pituitary gland to produce more MSH. When you wear sunglasses, this trigger doesn't happen, and you're more likely to produce LESS melanin and experience sunburn.