This may not be the kind of answer you look for, but this is an answer from my experience.
It is hard to pinpoint the exact usable number exactly, but for example, common data visualization tool Tableau uses 10 to 20 distinct colors. More exactly, it has a base palette of ten visually well discernable colors and then ten lighter tones of the same colors, achieving sufficient readability.
There is even a blog describing their design process (though it might be more of a marketing piece).
The catch is, there are other limits. While those 20 colors are visually distinct, my feeble human brain cannot hold 20 concepts in short-term memory. So even if I can see that two values are different (differently colored), I may not be able to (quickly, without looking them up in a legend) come up with what those colors actually represent behind them.
The limit for that is for most humans somewhere between 5 to 10. I have no citation handy for this, it's just that common knowledge thing, that everybody repeats (the common number is often seven for this). Obviously, some people are really good at this (like people who are able to count cards) and some aren't.
The thing to take away from this is, that since you usually design things for "average" people, you need to try to be as conservative as the subject matter allows. And then you have colorblindness, which might be a good thing to look out for – the more kinds of colorblindness you wish to design for, the fewer colors you will be able to use.
If ten or twenty colors is not enough, you can adopt other forms of distinctions, such as:
- Outline color
- Texture (hatching, cross-hatching)
- Striped versions (e.g. white and blue and so on)
Giving you almost unlimited possibilities. Keep in mind that the human mind will not work as well with higher numbers of elements, colors and so while you can use these, it doesn't always mean you should.