What to do when you find out your research result is wrong because it's based on wrong methods/results, after years of works?
One thing to consider is that showing fault in an "established" result is, in itself, an important result. If a student spent years working on a project, only to find that the results from their new work disprove earlier accepted results, that's worth telling other researchers (i.e. publishable). Especially considering there's probably dozens of other graduate students all working off those same results until someone tells them the results are not reliable. In fact, my father, an emeritus professor of mathematics, lists "counter-examples" as one of his areas of research. 

In the case of proofs and lemmas (i.e. case 1), this is clearly publishable. In the case of experiments, it's a little harder: you would need to make a strong case for your new experiment being substantial evidence that the previous results were wrong, rather than you just botched your experiment. But if you can make a solid case, it is well worth publishing. 

Sadly, the third case is not so good for the student. Assuming the student's colleague has not published yet, the research community does not benefit much from the student saying "hey I just realized my friend messed up". They should still tell their colleague and advisor so that the situation is communicated.