It's (arguably) not the market here that's the problem, but the patent. The patent means that generic manufacturers can't get in on the market and create a commodity out of it with a race to the bottom on price. The problem isn't the market, but the absolute lack of a market created by the exclusivity of a patent.
We need to find a way as a society that these companies can profit off the research and development of these drugs while still allowing generic manufacturers to do what they do best: create a real, competitive market to produce the drug in bulk.
Unfortunately I don't think there's any clear answers here.