Indeed. Companies have a limited time to recoup costs. Once the patent runs out, that $10,000 drug turns into a $500 drug. Forever. That benefit can't be ignored.
There are and some of them are an abuse of the system. However, most drugs pretty quietly go generic.
A good example is Lipitor. For Pfizer it brought in over $11B per year in revenue. Cost was around $150 per month. You can now get a month’s supply for $5.94 according to GoodRx. That’s a 96% reduction in the cost.