Human eyes have retinal cells that are sensitive to red, green, and blue light. Pixels on electronic screens use the same three colors to produce many apparent colors.
But a little thought (and knowledge of vector spaces) reveals that neither of these facts necessitates the other. There are infinitely many bases for a single vector space, and there are infinitely many sets of primary colors that could reproduce a large color gamut.
So why was RGB chosen as the basis / primary color set for pixels? Was it technologically easiest to produce pixels that create those colors? Is there a practical advantage to having the colors align closely with those that our retinal cells can detect? Or is there an external factor that singles out RGB as a "preferable" color basis for both vision and pixels (e.g., perhaps RGB allows for the largest color gamut).
Similar question here, but with unsatisfying answers. Very related to question #3 here, but it isn't addressed directly in the answers from what I can tell. That question is about why the frequencies of pixels are slightly different from those that our retinal cells are most receptive to, which adds yet another wrinkle to this topic.