This is the most common supply-demand and stocking problem across all industries. Surely you don’t think it’s as simple as that?
Good question!
My understanding is that that's how it used to work. Booksellers would buy as many as they wanted and sales were final as far as the publisher was concerned. It was on the bookseller to make sure they didn't buy too many.
During the Great Depression, bookstores were hit very hard and they didn't buy much. That in turn hit publishers. In order to incentivize bookstores to buy more copies, a couple of the larger publishers began to offer this deal where they would allow returning unsold copies. Booksellers loved it, obviously, since it greatly reduced their risk. Once a couple of publishers did this, the rest were basically pressured to follow since the booksellers so strongly prefered publishers who did.
Once booksellers got used to this deal, it became entrenched and now publishers are essentially stuck with it.