Why do scars get darker?

Multiple factors. Scars can get darker in people following a recent surgery or injury and a/ unprotected exposure to sun. B/ hormonal imbalance in some patients due to disease or side effect of medication. C/ darker skinned people - fitzpatrick skin types 5 & 6 and sometimes 4. D/ infections/chronic irritation of site can also induce darker scars to form.
Not always . Some scars are red , pink or lighter than normal skin occasionally they can be darker (especially in darker skinned people).
Melanocytes. Scars are rich in pigment producing cells (melanocytes). When these cells are exposed to sunlight, the skin darkens. It is best to keep the fresh incisions protected from the sun. Early scars are pink initially due to an increase in the vascularity of the wound. As the collagen is deposited, the vascularity recedes and the wound loses its coloration.
Inflamm or vascula. Wound get dark in response to inflammation which may trigger post-inflammatory hyperpigmentation. In the lower extremities this ca be aggravated by stasis dermatitis with hemosiderosis. In addition the increased vascularity may cause a dark red appearance termed hyperemia.