A factory worker takes a leg from a box and either clamps the paint mask on or holds it behind a mask that's fixed to the table. The masks are simply metal plates that are formed to fit around a particular part, in this case a leg, with an opening where they want the paint to be. Then they hit it with spray paint and put it down to dry. The mask only allows the paint to be applied at the opening. It's quite low-tech and you can imagine that every color requires a different mask and a different station to apply that color. That's why you see so few colors on figures because every color adds labor (cost).
For a part with such a small painted area it's easy to see why you could find several examples. All it takes is a bit of low light and a rushed worker - never in a factory, right? - and you have an unpainted part.
The painted parts are assembled at a later step and then sent on to packaging. All done by factory workers, not machines. The machines simply mold the parts or seal the bubbles to the cardbacks.