Why does the UK produce so many research papers?
It is very common for academics to not live and work in the country of their birth, and I would assume that this becomes the more common the more research active they are. Many of the publications from British universities will not have been written by British (born) scientists.
Instead, we see stable loops of the following type:
University X has a good reputation -> Productive researchers move to X -> a lot research gets done and published at X -> the reputation of X is good
The UK is home to many very prestigious universities, is not subject to language barriers and has mostly avoided historical disruptions to its research activity.
Many possible factors, but one that we can prove is that the UK has a disproportionate number of the best universities.
The Times Higher Education World Universities list states that the US has 110 of the 200 best universities worldwide, while the UK has 31, Germany has 20, and China has 7. Of course, this definition of "best" will invite lots of controversy, and will not only be based on research metrics -- but it does not seem impossible that the UK has the second-highest number of excellent universities worldwide. With this many excellent universities, we would expect a correspondingly high number of papers.
Why the UK has so many excellent universities is a different question for which it is harder to come up with hard evidence, though the first-mover advantage that @Arno suggests seems plausible. Excellent universities have an easier time attracting excellent researchers, so it's a vicious cycle.
One corollary: why does China rank so high with only 7 excellent universities? Well, in one sense they don't, China has ~20x more people than the UK. But beyond that, not all papers come from universities, and the Chinese government is investing very heavily in R&D.
Transforming comments into an anaswer:
One large difference between the UK/US and say Germany and France is that"showing off" is very much accepted in the US or UK, while generally frowned upon in say France (or Germany for that matter).
Having fully embraced the "publish or perish" dogma in the UK (I will guess most applies to the US too, but I have lived in the UK) means that there is a desire to produce as much "output" as possible to create a recognised brand, which hopefully attracts more research funding and international, fee paying students. This has become particularly clear in the UK in recent times, with an excessive focus on rankings for academic and their work, be it h-indices, "impact factors" and whatever they have come up with lately. (There is a new metric of some sort that one university uses.) This of course ignores the fact that research often needs time to be appreciated and utilised.
In part, such visibility can be achieved by employing lots of PhD students - and even large "Russel Group" universities are not immune to effectively becoming diploma mills, at least on the level of individual research groups.
Where the system comes full circle, is in the way that research funding is awarded: Often applicants for grants can benefit from showing a large publication record which again promotes the publication of quantity over quality. The simplest visible effect of this 'world view' is the splitting of large bodies of work into individual research papers rather than publishing a single comprehensive piece of work. Since two papers will, to the administration, look better than one.
Another difference between the UK as well as US and say Germany as well as France is the "job description" of universities. The primary task of a university in Germany of France is to teach - to educate teachers and to train/develop future researchers (or managers/leaders in the system of the French Grand Ecoles). Research takes place at research institutes which can be private or public. Examples of such research groups are for Germany the Max Planck Gesellschaft, Helmholtz Gesellschaft of Fraunhofer. In France we have CNRS but also the CEA.
In contrast, the UK universities, though registered as charities, very much operate like commercial entities. (For those in search of some controversy, an article about the pay of vice chancellors in the UK: https://www.theguardian.com/education/2018/mar/11/university-vice-chancellors-are-paid-far-more-than-public-sector-peers ) In addition, there is a certain desire amongst politicians to reduce state support for universities - one of the reason for the rise in tuition feeds from 3000 pounds per annum to 9000 a few years ago (around 2011/2012 I think). As a result, universities are required to provide as much income as possible through their own means. In the grand scheme of things universities have three main avenues to sustain funding: 1) tuition fees, overseas students pay especially well, 2) public research grants 3) industry research funding. Some institutions also have access to 4) trusts set up by former students who became wealthy or funds collected through donations.
Points 1 to 3 require public visibility of the university, be it to attract students or to justify why they should be funded through work. The easiest way to obtain such visibility is through papers - which in turn encourages the publication of more papers.