On the shelf, they either sell (yay!) or they don't (boo!) and staff pack them up and send them back to the publisher as 'returns'.
This makes way for the next months' books, which will be on shelf for a few weeks where they either sell or are returned. And so on, each month. Stores only have the capacity to stock maybe 10,000 books at once (I'm totally guessing) So they can't keep taking new books without shifting the old ones, either by selling them or shunting them home.
Some books - some lucky few - sell so well the store orders more in, and they keep selling so amazingly well they are on sale for months and months. These 1% of 1% of published books must be why so many people have the impression that if they want an author's book, it will be there when they go to the store, no matter how many months have elapsed since it was released.
My first book came out in April 2010 in the UK and the rest of the commonwealth. That's more than two years ago. It's not on the shelves of the average book store any more. This week I had a well-meaning friend say, "I really must get your book, but when I was in the shop it wasn't there."
This did not surprise me and I enlightened her about the shelf life of books being only marginally longer than the shelf life of yoghurt. She in turn was horrified that my book wasn't still for sale, "because it's such a great book."
Obviously e-books negate this problem entirely. Once an ebook is 'on the shelf' in the ether, it stays there. So yay, anyone with a reading device or app can read my (and just about any other author's) books any time they like.
There are also places on line where you can buy new and used copies. I'm sure you've heard of them *wink* they're responsible for the bulk of my sales. How else to explain why so many people in the USA have read Ondine when it wasn't technically for sale in their homeland.
But the stores themselves? That ship sailed years ago.