Here's the basics of how it works:
Take a brand new 40K car.
Imagine that car 3 years later, and with 30,000 miles on the clock - it would then be worth (say) 25K.
So, over 3 years it's lost 15K in value.
If a lease company can recover more then 15K from you over 3 years of payments, they make a profit.
How do they recover that 15K?
Firstly, they don't pay 40K for the car like you would. They have greater buying power than you do, and might only pay 35K for it. So they've already recovered 5K
Next they ask you to pay an initial lump sum of 1-2K - so whilst it's a 3 year deal, it's actually not, it's 3+36 months (39 months of payments for 36 months use!).
Effectively what you are doing it paying off the depreciation. So it doesn't really matter if a 40K car depreciates to 25K, or a 20K car depreciates to 5K - they both lose 15K in value, and that's pretty much all the lease company care about.
In order to protect the depreciation, they will place limits on the mileage. You can ask for 5K, or 20K miles, it doesn't matter, they will adjust the price accordingly to reflect the depreciation based on the number of miles (e.g. a 3 year old car with 15K miles will be worth more than one with 60K miles)
This is why an executive car often doesn't seem to cost too much more than a standard medium car - providing it's one of the brands that hold their value reasonably well, like BMW or Audi.
You're usually expected to take care of any accident repairs etc, all the lease company care about is that when you return the car, it better be in an appropriate condition for the mileage. Generally speaking that means 'very well looked after'.