From their diet. They eat foods high in beta carotene, mostly shrimp and algae. They also will eat mollusks (clams or snails) or crustaceans (crabs). They gather their food by gulping water with their beak and then straining the water and eating the leftover food. So, that being said, the color often varies between bird to bird in a flock.
Flamingos in a zoo are fed foods with the additive canthaxanthin to keep the color up to everyone’s expectations. The same is done with the pretty pink salmon you buy that is farmed and not caught in the wild.