By the way. there are other problems with your math: you're double-booking the cost of the payment and the depreciation of the car. Really, play around with a total cost of ownership calculator like Edmunds'. It will be enlightening.
Let's look at the F-150, the most popular vehicle in America. For the regular cab XL 4WD trim level, a 2020 model is $38K (close to your $40k) with a five-year TCO of about $44K. A 2015 model is $24K... with a five-year TCO of $41K. That's a difference in TCO of $50/month. Hey, if you can save $50/month, do it, but don't tell me you're saving thousands every year.
It's not the calculator is "wrong" in answering the question it asks, but that it's asking the wrong thing. Very few people want to buy an 11 year old car, so buying a 6 year old car and selling it 5 years later and doing the same thing again is overly penalized vs buying a 6-year old and selling it 10-15 years later (for much less), but only doing that once instead of two or three times.
> Why not compare it to a car you scrounged for free?
Because I can't repeatably find a reliable car for free. I can repeatably find many reliable cars for $8K in any city in the US. We paid $7500 for our 2005 CR-V in 2011. It was in overall great condition with high miles (165K-ish). It now has 220K miles on it and rust will kill it long before miles do (New England road salt).
Edit to add: I agree that my method above was double-counting depreciation. I should have stuck to cash items rather than including a non-cash item.
It is pretty tough, though, to get the cost of ownership on a car driven 15,000 miles/year below about $3,500/year. By comparison a new compact will be $5k to $6K per year in total cost of ownership. So if you are wondering why gold doubloons are not accumulating in the chests in your basement that much faster than they are for the guy who drives a new Honda Civic, that's why!
I know plenty of people who owe money other than a mortgage who are driving $50K+ cars/trucks and sometimes have more cars than drivers in the household (and both of those blow my mind for people with non-mortgage debt).