TL;DR: insurance isn’t gambling, but has sufficient similarities that it is better to be explicit.
Possibly under some circumstances. Consider insurance for a race car, if the vehicle wins it probably won’t be totaled, conversely if it is totaled, it probably won’t win. Lesser damage also decreases the chance of winning to some extent. Could it be considered gambling to insure the vehicle when the payout will depend upon a skill utilized in a sport?
The spirit or intention of the law is clear, but courts rarely rule on what the law meant, but rather on what it actually says. So, an explicit statement is added saying that regardless of any other factor, insurance isn’t to be considered gambling.
As for the difference between the two and why insurance is allowed while gambling isn’t. It’s for the same reason that damages from lawsuits aren’t taxable —- it’s not considered a gain, but instead countering a loss. Insurance isn’t a contest, where you risk your assets in order to get a reward. The insurer doesn’t get a reward if the event happens, and the insuree’s “gain” isn’t considered a gain, but rather a restoration to normal (or wholeness). Thus no one gains and there is no risk/reward taking place.
The insurance companies loss might be considered gambling, but they are expected to take that into account so that it is an expected expense and not a gamble. Pure applied statistics with a margin sufficient to prevent their expenses from out running revenue. States have laws requiring liquidity coverage ratio, in order to make sure that gamble isn’t too much for them to afford.