Why are you surprised?
You cannot represent an integer exactly in double precision if it is greater than 2^53-1. That appears to happen around n == 79.
So while there is nothing overtly wrong with your code, what is wrong is your assumption that you can use double preciion arithmetic to compute the result for large index.
If you seriously need to compute that result for larger indices, then you need to use a tool like the symbolic toolbox, or perhaps my own VPI toolbox, which can handle numbers with more than roughly 16 decimal digits. Or, you could write your own code, which might be less difficult than you may think. (Of course, I don't know how hard you think that is. This is indeed a conundrum.)
Finally, many such questions really don't ask to compute an actual sum, but they often ask for something like a remainder with respect to some given integer modulus. In fact, that is very doable in double precision arithmetic. In the case of your code, it seems you are actually computing and saving the numbers themselves, so it would not help here.