If you get a reliable used car, the maintenance cost are much lower than what you would lose to depreciation on a newer car. Shockingly, 2-3 year old cars wear out brakes, shocks, tires, batteries, belts and need fluids changed at the exact same rate as 15-20 year old cars. So really the only thing costing you extra on an older car are the big ticket items like an engine or transmission needing major repairs, which isn’t common (or that expensive) if you are talking about a reasonable car like a Honda Civic or Toyota Corolla. Even if you do have a big ticket repair (or a couple) over the span of 5 to 10 years owning an older car you come out way ahead of the depreciation + opportunity cost of a newer car.
I’ve got a 25 year old Toyota Tercel that I’ve had for 18 years, the purchase price in 2002 when the car was at 170k was $5k, 18 years later it’s at 330k+, still running fine and worth ~$1k, and over all that time the only repairs were a new clutch @310k, I’ve had the timing belt done twice, had the rear shocks replaced, spark plugs a few times, a couple new batteries over the years, one cv shaft, and oil changes. Oh, and I had to have the muffler welded back on after I damaged it on a logging road. That’s it. Maybe I spent $5k in 18 years on total maintenance.