So you see, I'm actually radically in favour of R&D.
Without the possibility of this outrageous profit we would just get less drug research done. That money would then be invested in something else. Drug prices wouldn't be so outrageous (probably), but we probably also wouldn't have as many treatment options. They might be too expensive now, but there's a chance they won't be in 50 years.
A massive amount of research is funded by public grants. iPhones are a famous example of a private-sector product almost entirely created off the back of public research. It is absolutely not true that private investment is required for pharmaceutical R&D.
There was a great video on this: https://www.youtube.com/watch?v=dnHdqPBrtH8 Asianometry - "Why the Soviet Computer Failed" (18m56s) [2022-07-07]
The welfare of the public today is not the same as the welfare of the public for all time. The Soviet Union couldn't compete on the development of computers, because the USSR was trying to optimize towards what could computers be used for then and there. It turned out that computers could be used for a lot more than what people thought of at the time.
Drug R&D and patents lead to enormous profits for companies, because they can charge outrageous prices for the drugs. But the benefit to the public is that now those drugs and the knowledge about them exist. That's going to have a cumulative positive effect for hundreds of years in the future.