This is price discrimination/segmentation. You want to sell the same product at different prices to different people. And because it is medicine, you do not want (too many) poor people to miss out on getting it, or at least you want plausible deniability for trying to make the product available to poorer people.
Enter manufacturer coupons, PBMs, and myriad government and health insurance reimbursement policies. The whole system is an emergent phenomenon of trying to deliver different quality/quantity of healthcare to different populations, but for political purposes, maintaining plausible deniability that society (via its elected leaders) is okay with some people getting less healthcare than others (or paying more or less than others).