Actually, it has a lot to do with depreciation because the market drives what the cars are worth on the wholesale market since dealers sell the vast majority of vehicles under 5 years old. What your vehicle is truly worth is whatever someone is willing to pay for it, but selling your car privately at dealer prices isn't going to move it very fast unless you have a popular vehicle.That's correct. Because they aren't going to pay the same price. They want to make a profit. Has nothing to do with depreciation. The dealer incurs expenses when they sell a car and they're going to recover those expenses.
This article explains why buying lightly used cars isn't always the best deal: https://jalopnik.com/stop-overpaying-for-lightly-used-cars-1828576980
As with anything, YMMV.