As someone who has worked for both an insurance carrier and an insurance agent, the reason people buy insurance is two fold: to spread risk out, and to get the benefits (when applicable) of approaching risk as a group.

What you are really doing when you buy insurance is you are buying in to a large group of people who are sharing risk.  You put money in that will help people when they take a loss, and in exchange get a promise of having your losses covered.  There is an administrative fee taken by the company that runs the group in order to cover their costs of doing business and their profits that they get for running the group well (or losses they take if they run it poorly.)

Some insurances are for profit, some are non-profit; all work on the principle of spreading risk around though and taking risk as a larger group.

So let's take a closer look at each of the advantages you get from participating in insurance.  The biggest and most obvious is the protection from catastrophic loss.  Yes, you could self-insure with a group size of one, by saving your money and having no overhead (other than your time and the time value of your money) but that has a cost in itself and also doesn't cover you against risk up front if you aren't already independently wealthy.  A run of bad luck could wipe you out entirely since you don't have a large group.  The same thing can still happen to insurance companies as well when the group as a whole takes major losses, but it's less likely to occur because there are more rare things that have to go wrong.  You pay an administrative overhead for the group to be run for you, but you have less exposure to your own risks in exchange for a small premium.

Another significant but less visible advantage is the benefit of being part of a large group.  Insurance companies represent a large group of people and lots of business, so they can get better rates on dealing with recovering from losses.  They can negotiate for better health care rates or better repair rates or cheaper replacement parts.  This can potentially save more than the administrative overhead and profit that they take off the top, even when compared to self-insuring.

There is an element of gambling to it, but there are also very real financial benefits to having predictable costs.  The value of that predictability (and the lesser need for liquid assets) is what makes insurance worth it for many people.  

The value of this group benefit does decrease a lot as the value of the insurance coverage (the amount it pays out) decreases.  Insurance for minor losses has a much smaller impact on liquidity and is much easier to self insure.  Cheaper items that have insurance also tend to be high risk items, so the costs tend to be very high relative to the amount of protection.  

If you are financially able, it may make more sense to self-insure in these cases, particularly if you tend to be more cautious.  It may make sense for those who are more prone to accidents with their devices to buy insurance, but this selection bias also drives the cost up further.  

Generally, the reason to buy insurance on something like a cellphone is because you expect you will break it.  You are going to end up paying for an entire additional phone over time anyway and most such policies stop paying out after the first replacement anyway.

The reason why people buy the coverage anyway, even when it really isn't in their best interest is due to two factors: being risk averse, as base64 pointed out, and also being generally bad at dealing with large numbers.  On the risk averse side, they think of how much they are spending on the item (even if it is less compared to large items like cars or houses) and don't want to lose that.  On the bad at dealing with large numbers side, they don't think about the overall cost of the coverage and don't read the fine print as to what they are actually getting coverage for.  (This is the same reason that you always see prices one cent under the dollar.)  

People often don't really subconsciously get that they are paying more even if they would be able to eat the loss, so they pay what feels like a small amount to offset a large risk.  The risk of loss is a higher fear than the known small, easy payment that keeps the risk away and the overall value proposition isn't even considered.