This is an excellent point. Like I said leasing is betting on the residual. Because of outside factors the actual value of the car is different than what you and the Lessor bet on. In this case it may be beneficial for you to buy and then sell the car at the end of the lease because the actual value exceeds the residual value. However, you shouldn't go into the lease expecting to buy the car out at the end of the lease.
If your car is worth more than the residual at the end of the lease then that just means that you paid more in deprecation during the lease than you really should have. Sure it feels good to get money back at the end but you are really just paying yourself back with your own money minus the interest that you paid to the lessor.
The best possible situation for a lease is one where the lessor has grossly overestimated the residual AND they have offered a very low money factor. Then at the end of the lease you turn the vehicle back over to them and let the bank take the financial hit for thousands of dollars of extra depreciation. That scenario almost never happens. However, it can happen. Most of the time if the car has a high residual then it will also have a higher money factor. If the car has a low money factor then it will almost certainly have a low residual.
Leases are not the horrific financial decisions that some people make them out to be. Don't get me wrong.
Most people get taken to the cleaners with leases***. However, the people that do their research and especially the people that can take advantage of the tax benefits can really make leases work for them.
I did an introductory video about leases on YouTube.