system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: The rainbow hat riddle, please explain how the solution makes 100% sure that at least one of the prisoners are right about their hat color?

This is the original version of the riddle: 

Seven prisoner are sat around a table and each wears a hat which is either Red, Orange, Yellow, Green, Blue, Indigo or Violet. There is no guarantee on how many of each hat there is; it could even be seven of the same colour.

Each prisoner can see every other prisoner, but they cannot see the colour of their own hat. Each has a piece of paper in front of them and they have to write down a single colour which is their guess as to which  colour hat they are wearing. If anyone gets it right then everyone goes free, otherwise they are all killed. As always, the prisoners are told the situation beforehand and they are given an opportunity to discuss a strategy.

How can the prisoners guarantee success? You might want to start with fewer colours and build up to a general solution. Answer below.

-

-

-

-

-

-

Answer: Label each person from 0 to 6 and assign ROYGBIV to 0 to 6 as well. Each person finds the sum of the hats that they can see and then works out what number they would have to add to the sum in order to get their personal number mod 7. (If you haven't seen mod before, I mean what remainder would you get if you divided the number by seven.) Whatever the number is that you have to add is what you convert back into a colour to guess. This guarantees success.

For example, let's say the seven prisoners are wearing ROGBRIG. Their sums of what they can see are [16,15,13,12,16,11,13]. They need to guess the numbers which, when added to these sums, give 0 more than a multiple of 7, 1 more than a multiple of 7, up to... 6 more than a multiple of 7. So in turn they guess [5,0,3,5,2,1,0] which corresponds to IRGIYOR of which the third person guesses correctly.

This method guarantees that all seven possibilities are covered by making sure everyone is just out of sync. A similar method works for n different colours worn by n prisoners.
gpt
When you take the sum of all hats according to your assignment of ROYGBIV to 0 to 6, when dividing that sum by 7, the remainder has to be one of 0, 1, 2, 3, 4, 5 or 6. That are 7 possibilities. You now assign each person one of those possibilities.

Let's assume that one of them covers the correct possibility. That means that he knows the remainder of the sum of all hats, and he also knows the remainder of all hats except his own. There can only be one color for his hat so that both of these remainders are correct. This only produces the prisoner's own color if he assumes the correct remainder for all 7 hats.

But remember that there were only 7 possible remainders, and that we assigned each of them to one person. This means that at least one person works with the correct remainder, and as I've described above, this allows that person to correctly guess their own color.

(In fact, there will only ever be exactly one person that guesses correctly, as everyone else uses a wrong assumption for the remainder of all hats)

As you've correctly stated, this works for any number of colors and prisoners. The mathematics behind it is called modular arithmetic.