So I remember this in my Econ 101 course thing.. eg. If all cars are legally required to be insured, insurers work off a population statistic to calculate cost of crashes/ individual issues (population statistics are public). If insurance is not compulsory, worse drivers insure, better ones don't, then insurers can't price off the population statistic because they only have a sample statistic (not public) of worse drivers on their books. I believe this was called the 'pooling problem' in my lecture, but sadly google comes up with entirely different ideas for that search! Please enlighten me! :) (if possible, some links to theory would be great, thanks!)
If insurance is not compulsory for all drivers there can be a case where the affected parties are unable to be compensated when an accident happens. In that case those affected by the accident wont have the means by which they can have their property replaced.
Insurance provides a service which guarantees a certain level of wealth for a party who is insured. Without insurance sub optimal transactions can take place making everyone worse off. This can be illustrated via an abstracted example.
1. Party A has wealth of \$50 and Party B has a wealth of \$100 and all their wealth is stored in their cars.
2. Party A and Party B both get into a car accident.
3. Party A destroys Party B's Car and legally owes Party B \$100
4. without insurance Party A is unable to compensate Party B and loses all his income.
This whole issue can be avoided via the purchase of car insurance. So the law requiring all drivers to have insurance actually leads to a net increase in welfare for all involved because it allows legally required transactions to take place.