In the following tree ~/.claws-mail/tagsdb/#imap/<account>/<deleted-folder-name> <deleted-folder-name> are names of IMAP folders which existed but were deleted long ago. This means Claws keeps them although they are not related to any actual data.
I just noticed that folderitemrc also keeps data for deleted folders.
Can you reproduce this on a freshly deleted folder? Over here, deleting an IMAP folder also deletes the corresponding tagsdb dir.
I can confirm that deleting the IMAP folder also deletes the corresponding tagsdb dir. However the lines for that same deleted folder remain in folderitemrc and that file grows and grows. Currently my folderitemrc is >540KiB and there are many many folders mentioned in it, listing folders for accounts which have been deleted long ago. It would be great if you could suggest a way to clean that up when fixing the bug.
Another thing I just noticed: There are older empty subfolders in 'tagsdb/#rssyl/My Feeds' for folders and feeds which I have deleted long ago. I tested creating and deleting a new folder inside 'My Feeds' and it is removed like with IMAP but the old ones remain. I suppose at some point something may have been fixed in regards to folders (but not for folderitemrc). Still some way to have all those clean and corresponding to the actual data seems necessary.
I can confirm even with 3.16.0 that tagsdb/ contains obsolete subdirectories and .claws_tags files therein. One particular subdirectory is named after the former login address of an IMAP account that I later renamed to a different alias address of the same mailbox. There is a subdirectory named after the new address as well, but the .claws_tags file therein is considerably *smaller* than the older one, suggesting that tags got lost. If this bug is too rarely encountered (or rather: reported) to be addressed, I would nevertheless appreciate any insight as to how such discrepance can be prevented and/or fixed manually.