The author Anonymous has 74,305 publications in the Scopus publication database. Those include 32,476 peer-reviewed articles, most from the 1980s and 1990s.
Why would anyone write a peer-reviewed paper anonymously?
I searched for the author Anonymous in PubMed (the life sciences publication database), and found 26 results, which shed some light on your question.
Some paper titles:
So in many cases the authors are describing a sensitive experience or medical condition they have and they do not want others to know about. Alternatively the author could be a whistle-blower. It may also be used in some cases where the editor wrote the piece but does not take credit, but I am guessing this is usually not the case.
In one case that I know of (Anonymous, 1969; J. Glaciol) the article summarizes a then new report on terminology. The paper is published in a high impact journal in the field but is not a research article and not a review article, just a summary. The purpose was to inform the community and after that people reference this paper rather than the report, which before internet was hard to get.
The reason why the authors were anonymous in this case was that they felt no-one in particular should be personally associated with this summary (get credit as if it was a scientific paper when it really was not). The report was made through a large international effort with international peer review. So from this perspective, the Anonymous author has a function to fulfil. The material becomes possible to reference and it is not tied to a person but a community. It would, of course be possible to call the group working on the report something and then use this communal name instead of "Anonymous" as is also sometimes the case in larger projects.
In one famous case, a statistician had to use a pseudonym (he used A. Student instead of Anonymous, but basically the same idea). William Gosset was employed by Guinness as a researcher and I'll just quote Wikipedia here:
Another researcher at Guinness had previously published a paper containing trade secrets of the Guinness brewery. To prevent further disclosure of confidential information, Guinness prohibited its employees from publishing any papers regardless of the contained information. However, after pleading with the brewery and explaining that his mathematical and philosophical conclusions were of no possible practical use to competing brewers, he was allowed to publish them, but under a pseudonym ("Student"), to avoid difficulties with the rest of the staff. Thus his most noteworthy achievement is now called Student's, rather than Gosset's, t-distribution.
This paper was published anonymously as a critique for lack of mathematical foundation on optimization literature. The paper shows a ridiculous algorithm that meets all accepted criteria for having a sound theory supporting it.
Editor's note: This manuscript was transmitted, torn and tattered, to Mathematical Programming by Philip Wolfe with a letter, stating, in part: “I have refereed many papers which proposed optimization algorithms without studying their effectiveness; it will save me much time to have here a single reference I can cite, saying ‘This algorithm solves all the problems yours does and, on the available evidence, equally well.’ I therefore recommend publication ⋯ and hope that the author will come forward to receive ⋯ what he richly deserves.”