Go ahead and publish --- advance the science
I recommend you proceed with research and publication for this result. If the result is new and advances the field (and it certainly sounds like it would) then it is desirable for the advancement of knowledge that it be developed and published. Depending on the overlapping research by your classmate, there might be scope for a fruitful collaboration, or it might be best to go ahead and publish your existing result without further input. The ideal ethos for science is one that recognises the value of that knowledge as being something above the importance of personal advancement and careerism. We all need to get used to the fact that scientific advancements may occur in ways that retard our own personal career advancement, but which give broader social benefits. Your classmate will have to get used to this fact, and there is no better time to start getting used to that than now.
If you were to mothball your result in the interests of keeping the problem open for your classmate then you will be delaying a scientific advancement in your field, purely on the basis of careerist considerations (albeit for him, not for you). There is no guarantee that your classmate will rediscover your solution, and his work might not be as good a solution as your own. The longer the publication of a valuable solution to the problem is delayed, the more time and efficiency is lost when others encounter the problem you have solved. It is also a loss of efficiency if your classmate continues working on his own solution without becoming aware of this new solution, which might render some of his research redundant, or set him on a path to further improvements. Publish your solution and give him the chance to adapt his own research to the new state of the science, without delay.
It is likely that your classmate will indeed experience some negative feelings about having someone else solve a problem he had been hoping to solve. It is perfectly natural to feel disappointed when you work hard on something and the output of that work turns out to have less value than you thought it would. (I once spent a summer researching and solving a problem that I thought waas a big deal and would be a great paper; to my disappointment, it turned out that I had rediscovered an old result.) Your classmate will need to adapt his own research to take account of your solution, which might or might not set him back in his PhD candidature, but which will give him an opportunity to advance further from a higher state of knowledge. If he is mature enough to see the bigger scientific picture then his negative feelings will be limited to his own disappointment, and will not manifest in any negativity or ill-will towards you.