Tyler Cowen suggests possible causes:
1. The ordeal of studying and possibly finishing is extreme, and extreme ordeals depress people. . . .I find number 5 interesting.
2. The task of studying and possibly finishing is correlated with a kind of extreme lassitude, and that in turn is correlated with depression.
3. Graduate students become depressed as they realize they have chosen poor life paths.
5. Graduate students are undergoing a transformation of their personalities, and being turned into intellectual elites, but this process is traumatic in several regards, thus leading to frequent depression. The chance of depression is part of the price of admission to a select club.
But I think the main cause is in the kind of person who elects for graduate study. People who opt to spend several years of their lives in advanced study of arcane matters are not normal. Their abnormality makes them more interested in theoretical puzzles than most people, and also more prone to depression.
It may also be that a sense of being stuck and not getting on with life as one ought weighs on people; I loved graduate school at first but after three or four years I was ready for it to be over, and yet still it went on.