This is the key. Everybody constantly says you're great cause you are so smart. Your value and identity is build on that for half your life at that point. If you suddenly can't deal with something - it means you're a fraud. Better to fail because you haven't tried ("you're so smart but so lazy") than to fail after a solid try ("you are not special after all, you're just a regular kid").
And for a while it works - you put less effort not to risk being "found out", you get same effects (or even better effects because if you haven't tried and still got A it means you're that much smarter). Then it stops working and you're absolutely miserable never having learned to put in the work.
I don't know how to "fix" this problem, I think the first step is to stop showering gifted kids with praise.