Some of it is being in the right place at the right time. A field has advanced to a certain state that some key insight is "ripe" for exploration.
Some of it is luck. Things just "come together" for the student.
Some of it is great advising, and some of it is being at a university in which there is a lot of intellectual discussion going on.
But research, and the great results, isn't something that can be scheduled and necessarily builds up incrementally. It takes insight, Eureka, that most trained researchers are capable of, given the right environment.
Finally some of it is just that the great work is recognized after the fact as others find it useful.
Note that my perspective is mathematics and computer science.
My daughter's dissertation was a "great work" in philosophy because she had the chutzpah to take on and refute a certain conventional wisdom held by the "great men" of the time. Risky, that.
But the riskiest path of all is to try to solve some classic unsolved dilemma that has been worked over by a generation or two of researchers. Getting a "win" there is partly magic, as the existing papers don't seem to get very close to a solution. New researchers are normally advised to avoid putting too much work into such problems until they have an established position in which failure to finish isn't devastating.