It's just that morally we treat insurance differently; and society has developed some moral and ethical rules around this topic. But because the mathematical structures are so similar, you can guess that the moral rules have lots of grey areas.
(Similar for financial derivatives. Eg farmers use wheat futures to lock in the prices for next year's harvest today. Speculators use the same futures to 'gamble' on prices.)
Some whole-life policies carry cash value and are an investment vehicle as well, so you can potentially make money on them surviving as well. This seems ethically-better, but most life insurance is term life that doesn't have this investment upside.
The mathematics are similar from the ensurer/casino side. However:
1. The happiness impact of losing 5x your net worth (house burnt down, eternal debt) is likely much bigger than gaining it.
2. It's harder to repeat sell insurance to someone until they are broke, compared to a slot machine.
If you take bets on how companies will do in the future, it's called finance or investment services. If you take bets on human misery, it's called insurance. And if you take bets on sports, it called gambling.
Businesses in all three have, for good reasons, the reputation of being predatory.