- On the "Sending books to devices" page of the preferences, the "Metadata management" option has to be set to automatic.

- On the driver configuration options, the shelves column field must have the name of a column. If this is not set, the driver does not do any shelf management.

The other reason that seemingly empty shelves will not be deleted is if you have been using an SD card. If you use an SD card and put the books onto shelves, when you eject the card, the device keeps the records about the books in the database. That makes it fast to reinsert the card with a few extra books. The empty shelf removal sees these as still on the shelves even though the card is not seen.

If the does not fix or explain things, could you please run calibre in debug mode and post the log? To do this, right-click on the preferences button in calibre and select "Restart in debug mode". Calibre will restart and display a message about the debug log. Dismiss the message and connect your device. When the jobs to collect the details of the books on the device have finished, close calibre. The debug log will then be displayed. Post the full contents of the log.