This is strange because you said you’re using a Spam mailbox under “On My Mac,” but the error message seems to indicate an error moving messages to a Spam mailbox on the IMAP server. To be extra clear about what’s doing what, I would suggest creating a mailbox under “On My Mac” called SpamSieve and change the SpamSieve rule in Mail’s preferences to use that mailbox. Then see whether the error message that you receive changes.