Early on in my retail career I was told that this was a tax thing: that companies could write off waste easier than they could with donations or marking it down excessively. If true it's still a shitty thing to do but we clearly need to fix whatever law/code/whatever allows it.
A lot of stuff got thrown out this past year due to COVID shutting down or slowing down donation centres my company used.
The hard thing is that what we're essentially seeing is the word "waste" being overused. A big tax credit for waste is a great idea; you don't want to punish a business for production of goods (which means jobs), so you're covering them a bit if there are unsold items that will expire in some way (degrades, batteries die, something organic that rots, etc...).
Here, the reason these items are "past sell-by" is the warehouse is out of space. The items themselves aren't bad, but they're now not worth the space they take up. That's not really in the same spirit as the definition above.
If the tax thing is true it's doubly baffling because, like… just give companies a slightly bigger credit for donating than tossing and you're good to go. I'm sure it's not as simple as that but there's no practical reason for it to be the way it is. Companies will do whatever gets them the most money.
Bigger credits can help, but I think you also need to set up or incentivize as many donation locations as possible, for all types of items. It's not like every place that takes donations will take literally anything, and figuring out the logistics of who will take what is probably a full-time job. The govt should get that kind of info together (and if there aren't donation centers for items X,Y, and Z, then make them).