Spam not going to spam folder

From what I’ve seen, errors like this are caused by two interacting bugs:

  1. Updating to Mac OS X 10.11 sometimes causes Mail to create a duplicate IMAP account where one didn’t exist before. The new account is marked as inactive, so you wouldn’t ordinarily see it unless you go to the Accounts section of Mail’s Preferences window.
  2. If you have two accounts with the same name (the Description field), Mail’s AppleScript support (which SpamSieve uses to move trained messages) can get confused and report that error when the script tries to reference a message in the inbox.

The workaround is to either rename or delete the inactive account so that all of your accounts then have unique names.