Recommending a paper for rejection, then publishing my own My question is similar to this one

I am an editor for a lousy paper and I found a better algorithm than theirs. Must I share it with them?

although there are some small distinctions that (I think) make for a different question, which I write below:

I was a referee for a paper submitted to a high-caliber journal.  For two cycles, I had recommended "major revision" because I felt like the problem was a useful one, but the writing was a mess and the methodology was needlessly complicated.  After the third revision, I recommended "reject" because I worked through some analysis on my own, over the course of a couple of months, that the methodology was actually fatally flawed in a way that made the manuscript unpublishable for this particular journal.  I shared this finding with the authors and they were understandably upset (and quite contentious about it), but they did not identify any flaws in my reasoning.  The editor wrote me a note to thank me for an "extremely thorough and helpful" review.

In the time that has passed since then (just under a year), I have continued refining the analysis that I did, to the point where I now have a result of my own that is probably publishable in a lower-tier journal.  The authors of the original paper have not made their manuscript available online, with the exception that the contents of the original paper are one of the chapters of the student co-author's dissertation, which is publicly available on the university's website.

Is it ethical for me to submit my paper to a journal, citing the dissertation and giving it credit for introducing the problem?  On the one hand, the material that inspired me to study this problem has been made public, but on the other hand, I feel guilty for the amount of time that the authors spent on revisions that were ultimately fruitless, and this could lead to the original paper having a much more difficult path to eventual publication (somewhere).
Is it ethical for me to submit my paper to a journal, citing the dissertation and giving it credit for introducing the problem? 


Yes.


  On the one hand, the material that inspired me to study this problem has been made public, 


Yep, that sounds like a winning argument to me. If it’s public, then anyone may use it as inspiration for new research. Credit must be given to the source of course, as you yourself say you intend to do. The fact that you came to learn of the ideas through your work as a reviewer a year ago is irrelevant and I see no good argument in favor of disclosing it. The ideas are now public, period.


  but on the other hand, I feel guilty for the amount of time that the authors spent on revisions that were ultimately fruitless, 


Guilt is sometimes a worthy emotion, but I don’t see what role it has to play here. As the reviewer, you did your best to shepherd the paper along on its route to publication in the hope that it will reach the threshold of publishability, selflessly investing time and energy with no expectation of getting anything in return. Sadly, things didn’t work out that way, but it sounds like everyone involved acted in good faith and no one is to blame, least of all you. It would have been very different if you had developed the follow-up research while you were reviewing the paper and intentionally sabotaged its publication in order to publish your work first, but that’s clearly not what happened.


  and this could lead to the original paper having a much more difficult path to eventual publication (somewhere)


That is too bad, but that is life. For you to voluntarily refrain from publishing a good scientific idea just to leave elbow room to other people who may or may not ever want/need/make use of it, would be damaging to yourself and (presumably) to the scientific community.

As for the idea of offering coauthorship to the authors of the original paper, that sounds like a reasonable option to me, but based on your account I don’t see that you have any ethical obligation to do so. In fact, depending on whether you feel they really deserve that type of credit, that may itself border on the unethical practice of gift authorship. Whatever you end up deciding, in my opinion coauthorship should not be offered as an act of charity or for irrelevant (even if true) reasons like “PhD students need to eat” as someone mentioned in a comment.