They tighten up the switch housing by reducing movement of the top casing. This reduces play in the stem just a little. Not a lot, but it's nice to do if you've got the switches open already.
It's most noticeable on switches which have less of the stem slider area in contact with the rails in the bottom casing and rely on the top casing to help stabilise the stem, like the clicky switches (blue, green and white). Less noticeable on tactile and linear switches (brown, clear, red, black, etc.)
The colour is just for looks.