Apple Mail: Apply Rule to a Folder
I figured out it's at possible to apply rules to emails in drafts, sent, junk, trash, archive or other IMAP folders by selecting all messages and selection Message > Apply Rules.

The issue might have been that the spam emails are flagged as read on the server before they are loaded by Apple Mail and that Apple Mail doesn't apply rules to new emails if they are flagged as read already.