Also, there's literally a government regulator that controls entry.
It isn't just patents either, the FDA will grant exclusivity periods for other reasons, and so on, but it then doesn't have much power to examine pricing. It's because our Congress is stupid (I mean, that's the terse summary of it).