Rainbows have seven colors because they are they colors of the spectrum. It's the colors that are found in sunlight.
It's the same result you get when sunlight passes through a prism. It's because of refraction. It separates sunlight into its constituent colors. I'm trying to explain it in the most basic way.
There's a more complex way to explain it but I think you'll do just fine with this.