What do PhD researchers generally do when someone else solves their problem? Suppose, someone is at the 3rd year of his PhD program. I.e. he has passed more than half of his time in his degree program.

Then suddenly, he comes to know that someone else already solved this problem and published a research paper in a journal last week.

What do researchers generally do in such cases?
If you work in a "hot" area in some field this sort of thing is fairly likely to occur. A lot of other people are also looking to make advances simultaneously. This is what makes it "hot". 

What happens for the degree depends on the local situation. In some fields and with some advisors it is a true setback and the student needs to either start over or continue on looking for "fresher" results. In other situations, the judgement might be that there is no problem and you just finish. But that assumes that your research is essentially done (not in the middle) and all you need to do is write it up. In those situations the degree might still be awarded. 

I know of a case in which two people did the same work at the same time, independently of one another and submitted it to the same CS conference. It took faculties a year to determine that it really was independent work and both received degrees. Both students went on to become fairly prominent - and friends, I think. This was an example of a question being asked that was fairly "hot" and many people wanted to see it answered. So the independent searches was easily understandable. 

But for a student in the middle of research, with few results so far, it is a setback. The first thing to do is to talk to your advisor about the options. It may be that a slight redirection will serve. It might be that an extension of the published paper will serve. The student presumably knows a lot about the (sub) field and so should be in a decent position to recover, though it may add time to the quest. But starting over on a new problem should be only the last resort considered. 

But it doesn't mean failure in any sense. The student was on the right track, at least. If you are really doing research, there is no schedule for when the results appear. It is a reach into the unknown. 

With the consent of the advisor it might even be worth forming a collaboration with the other authors. That might work better in some fields than in others.