I think depends on the brand. Some cars loose depreciate very fast: great to buy used, bad to buy brand new. Some are the opposite.
If you are buying a Toyota, makes more sense to buy brand new as they don`t really depreciate. Sports cars used to depreciate a lot, but after Covid that seems to have changed a little bit. When I bought my GR86, I paid MSRP, whereas 2 years old used ones were being sold for MSRP +3K at least. But also at that time if you bought a Jaguar F type that was 5 years old, you would have paid the half of the MSRP.
Again, boils down to what car you are buying. Buying a luxury car: buy used. Buying a "reliable" car? Buy new. People seem to rather pay %30 more when buying the car rather than paying 10% of the car`s value later down the line for repairs. Behavioral economists study that behavior through insruance premiums.