This question is based on a paper I came across a couple of years ago written by a famous professor who had developed a method to solve a certain problem. His method was not the first or the only method but it has some advantages and it is widely used in industry.
The paper I came across was written with sole purpose of finding flaws in a method for solving the same problem that someone else had published 15 years later.
Regardless of who was right, is this the proper way to deal with a flawed paper? This seems a bit weird to me. Do journals even normally publish such papers? Aside from citing the (presumably) flawed method, he also specifically named the authors in the abstract.
This worries me a bit because I plan to publish another method of solving the same problem soon, and although I have confidence in my work I don't think it's bullet-proof. I feel that if such a paper was written about my research it could have a significant negative impact on my future career if that was what popped up when you googled my name.
I have come across such papers. One notable one was written to show that the proofs in a handful of highly cited papers are wrong. He then proceeded to fix them.
In general, I think every paper that solves the same problem MUST highlight the weaknesses of existing methods. Now, whether the 'highlight' is done with tact is up to the authors. Some are arrogant and their comments serve to show how 'smart' they are.
In conclusion, yes such papers get publish because they contribute to the body of knowledge. How a paper is presented may irk some reviewers/readers, but if the contribution is significant, I doubt anyone cares.