The above poster is right; you can look at it from a utility function point of view.
People know that chances of winning lottery is very slim,
i.e: their expected gain is way below 0. However, the expected utility function will be positive.
Overall, you are over paying when u are buying insurance: your expected loss is less than your premium, but because your utility will be higher with insurance, people will buy insurance.
Think of it this way:
If you buy car insurance, you pay $100 premium and u have no loss, your utility function might be negative.
But if u pay 100$ and you have loss of 1000$, your insurance will cover it so your loss is still 100$ (the premium)