The reason is simple: genes coding the long wave opsins (light-sensitive proteins) in these cones have diverged from copies of the same original gene. The evolution of this is very interesting.
Mammals in general have only two types of cones: presumably they lost full color vision in the age of dinosaurs since they were primarily small nocturnal animals or lived in habitats with very limited light (subterranean, piles of leaves, etc.) Primates are the notable exception, and have evolved the third type of cone, enabling trichromatic color vision, as a result of their fruitarian specialization and co-evolution with the tropical fruit trees (same as birds, actually).
So, what's interesting is that New World and Old World primates evolved this cone independently. In Old World primates the third cone resulted from a gene duplication event on the X chromosome, giving rise to two distinct (but pretty similar) opsin genes, with sensitivity peaks at very close wavelengths. As a note, because these genes sit on the X chromosome, colorblindness (defects in one or both of these genes) is much more likely to happen in males.
New World primates have a single polymorphic opsin gene on the X chromosome, with different alleles coding for different sensitivities. So, only some (heterozygous) females in these species typically have full trichromatic vision, while males and the unlucky homozygous females remain dichromatic.
Decent wikipedia article on the subject: https://en.wikipedia.org/wiki/Evolution_of_color_vision_in_p...
Types of opsins in vertebrates: https://en.wikipedia.org/wiki/Vertebrate_visual_opsin