If there is an event that happens 1 time in 100 that costs you $100k and you pay $1.05k to insure against that would have a negative expected value in money terms but positive expected value in utility of money terms. It's hard to model utility of money curve, economists often use logarithm for convenience (it's easy to do math on logarithms) but whatever the specifics we know the function is concave. No one rational is going to flip a coin for their net worth or any significant part of it for example.
With this in mind insurance is a service worth paying for as long as the fee is lower than utility you gain from it. In a theoretical case that the fee is 0, that is expected value of money when taking the insurance is 0 you should always take it. In the opening example of 1 in 100 event that would be $1k USD fee.
Gambling is the opposite: you voluntarily stake money on event that wouldn't otherwise affect your financial situation. This decreases combined utility of you and your counter-party. Utility is higher if you both have $1000 than if one of you have $0 and the other $2000 for example.
Gambling, like excessive drinking or other activities that hurt the population as a whole is viewed as immoral by many moral systems. I think it's hard to argue against that - the more gambling there is the worse off the population is going to be. Not so with insurance.