Extended warranties or service contracts are pure math. Someone has analyzed failure rates and expenses and figured out the statistics on how often things fail and what they usually cost. They then price the service contract wholesale to the dealer or seller so that on average, they will pay out less in claims than they take in from premiums. Then, the dealer who buys the contracts "wholesale" sells them to you at another markup, often substantial.
Let me assure you, some very smart people with a very large base of data to draw from have priced the warranty where it is to make money off you. It is simple as that. They are not in the business of losing money. The bottom line is, they pay out less in claims than they take in via premiums. At least, the vast majority of the time. Yes, on occasion they are wrong, and occasionally one person out of a hundred has a really expensive failure that blows the curve. But, on average when all is said and done, they are again paying out less than they are taking in. Dealerships make HUGE money on service contracts. So do insurance companies, etc, basically anyone selling them.
You may indeed be one of the minority of people who benefit and come out ahead. You may have a $4000 repair and the contract cost you $1500. Everyone has an anecdotal story like this, kind of like everyone has a story where someone survived a crash because there were NOT wearing a seat belt. Odds are, though, that you are safer with a seatbelt, and odds are that you will keep more of your money when you don't buy extended service agreements.
It's like a casino, really. The vast majority of people lose. Yes, the odd person wins big once in a while. On average, though, if you gamble long enough, you will be a net loser and the house a net winner.
What you are getting with extended warranties, though is peace of mind. This has a value to many people. You may not care as much that you ultimately recovered your premium or not...it is the fact that you are driving worry free, you already wrote the repair check basically ahead of time, and you have a known period of covered time to breathe easy. This psychological reason would probably be the only valid reason to buy a service contract strictly speaking. Math wise, odds are against you, and there are a lot of highly paid actuaries out there studying the data and setting up the contract pricing scales who are paid to make sure the company wins overall.