By default, spam messages in Yahoo Mail are deleted forever after one month. (However, when I checked the setting for my account, it was set to one week, and I know I've never changed it. Yours may be similar.)
Settings > Security, you can change that value to be one week, two weeks or one month, but you can't set it to never.
Spam messages deleted after the deadline are deleted permanently; they don't get moved to your trash folder. Even so, messages are regularly deleted from the trash folder as well. There is no mention of the exact frequency, but the Help says "Yahoo Mail regularly deletes the contents of the Trash folder. This isn't a setting you can change."