ThunderBird apply a filter to incoming messages in all IMAP folders including SPAM folder and other sub-folders

When you create filter in ThunderBird, you are able to manually run it on any folder and sub-folder that you want. But if you want it to run automatically when messages are retrieved, it will only run on the Inbox.

My host causes some of my mail to automatically be placed into a SPAM folder on the server, before I can retrieve it.
You can not use POP to retrieve mail from any folder on the server except the Inbox.
However, you can setup IMAP instead, which will allow you to retrieve all mail from all folders, including the server side Spam folder.

In order to get the filter in Thunderbird to run on all IMAP mail retrieved in all folders and sub-folders, including spam folder, you need to add a custom preference to the Config Editor.
If you are not familiar with how to access and use the Config Editor, I will leave it to you to research that before you continue, as I will assume you already know how to use it.

OPTION 1 – Turn this on for ALL mailboxes
Add a new STRING preference as follows (You must choose STRING and not a boolean in order for it to work properly):
   mail.server.default.applyIncomingFilters
and set it to:
   true

OPTION 2 – Turn it on for a specific mailbox only
You will first need to search preferences for “mail.server.
You will then see that there are settings for mail.server.server1.xyz, mail.server.server2.xyz, etc
You will need to look for the name of the mailbox you want to turn on the filtering for, and determine whether it is server1 or server2 etc
Assuming the mailbox you want is server2, then
Add a new STRING preference as follows (You must choose STRING and not a boolean in order for it to work properly):
   mail.server.server2.applyIncomingFilters
and set it to:
   true