Should read up on the history of medical insurance, e.g. blue cross blue shield. The idea was that expensive payouts can happen early on during someone's coverage, before they have a chance to build up savings. No one wants that to happen to them, so if everybody is in the pool of people who will pay for coverage, that risk is mitigated by being spread over a large group who only need to pay in a little at any time.
Rich people or institutions who can afford to self-insure don't need insurance.
This original insurance was non-profit. The capitalist insurances are the ones realizing they can choose to only cover people who aren't likely to need payouts, and profit off of the difference between pay ins and pay outs. I also agree this is a morally dubious system.