It's a form of price discrimination trying to separate out different customers with different characteristics to make more money.
Whilst not a perfect comparison a simple monopoly will restrict supply to force up the price and make greater margins. The real world is more difficult but my point is that selling more doesn't always make sense.
People who book last minute are likely to have inelastic demand, in part due to a lack of available substitutes, and also a high willingness to pay. (Although these characteristics don't imply the others.)
Better to have empty seats to sell high rather than fill the plane with cheap seats. And as others have highlighted if you discount aggressively late then some people will hold out and book late having learnt the trick.
There is reams of information out there on yield management and price discrimation if you use your favourite search engine and have a desire to read.