In that sense, a restaurant is quite an optimal place for handling it smoothly. In any store where the customer collects the stuff they want to buy and then marches to the cashier, things are different. The cashier might say they already shut down the system, which would result in the customer having to give up, but I bet they would then just leave all the stuff they had collected right there. The store staff would then need to deal with the items, return them to the shelves, which actually takes more time than allowing the customer to buy them. The library is kind of same: if the last minute person collected a bunch of books, refusing it would still require taking the books back to their proper places. What they should refuse is all that talk and further book inquiries, but since it's Japan, they don't simply refuse anything.
I feel like this all comes down to a tacit understanding that new customers don't enter a business/office during the last minutes. The last minutes are just for the existing customers to exit. However, inconsiderate people don't care about any tacit understandings.