Not sure why Yahoo Mail doesn’t allow you to block spam in IMAP, but in OS X’s Mail App you can set the preferences to delete spam upon closing Mail App.
With the Mail App open select Preferences, then highlight the account and choose Mailbox Behaviors and under the Junk option select “Delete junk messages when: Quitting Mail”
Once you close out of Mail App the Junk messages will delete. You can use this setting with other email providers. I use it also have set this in iCloud.