https://en.wikipedia.org/wiki/Supply_and_demand
The people setting the prices on expiring goods are gambling on where the supply and demand curves will be, and they're probably wrong so they go up and down. Next time you reserve a hotel room, check the prices right before your cancelation window expires. There's a good chance the room prices have dropped.
Edit: Also there might be some price discrimination involved. Since each buyer values goods differently, it is most optimal for sellers to charge the most each buyer is willing to pay, and it could be true that those seeking last minute flights are business travelers willing to pay more (or those with emergencies willing to pay more). Also works with grocery store coupons and discount codes, those whose time isn't worth looking for coupons won't bother.
BTW I think it's appalling that overbooking is allowed in this age of nonrefundable tickets. You've paid for the seat; whether you sit in it is your business. In the old days of regulation most tickets were fully reusable, and overbooking harks back to that time.
> Doesn't buying plane tickets in advance let airlines plan capacity better?
was that whatever airlines are doing to plan their capacity doesn't seem to work very well. In support of this vague claim I adduced a news incident, very very snarkily (for which I apologise), but honestly in a spirit of discourse rather than simply of attention grabbing.