Medicare didn't provide coverage for prescription drugs until the adoption of Part D. That is structured differently than other parts of Medicare. Instead of the government serving as the insurer directly, the government subsidizes premiums for a private Part D insurer. The private insurer can and does negotiate drug prices.
The fact that Medicare can't negotiate prescript drug prices is often invoked as a talking point, but Medicare prescription drug spending accounts for a relatively small proportion of. overall Medicare spending: https://www.heritage.org/medicare/commentary/good-and-bad-id... ("Consumer choice and competition have made Part D the rarest of government programs: one in which spending hasn’t spiraled out of control. In fact, government actuaries report that federal general revenue spending on the program was $67.8 billion in 2018—that’s less than what it spent in 2015 ($68.4 billion).").
A point in case is the Hep C vaccine: https://www.medicalnewstoday.com/articles/323767#drug-types-...
I'll admit that profit seeking would work better* in a society that doesn't have a strong state or other coordinating body, but given that one exists to counterpose our existing system is not reasonable.
EDIT: * In the sense that products might be produced at all. Without a strong regulatory body, the market would be flooded with snake oil medicine and the average consumer would not be able to make heads or tails of things. This is because it's much cheaper to make a fake medicine than a real one, which is what profit optimizes for: the cheapest solution with the highest payoff for the seller regardless of costs not borne by the seller (such as death and destruction writ large).
There is an issue with some old out of patent drugs that costs a lot despite being very cheap to manufacture, but that typically has to do with FDA certification deciding who can be allowed to produce what, which is also expensive to obtain.