This is because purple was extreme difficult to produce as a dye, which is also why it was only worn by the royals as symbol of their wealth.
Many flags are extreme old, so most contain the colors there were relative easy to produce.
red symbolizes blood, anger, the sun (in Japan) and/or passion, blue the waters and sky, yellow the sun green land (like leaves and clovers) and prosperity.
Also, some color are harder to see from a distance or may fade rather easily.