How do I prevent spam from appearing in Messages on iOS?
It’s too late for iOS to reclassify previous contacts once they are in Known. For those, make one contact called Telemarket Spam and block that contact.

https://apple.stackexchange.com/a/345784/5472

As more trickle in, take manual action on them if you don’t want to engage your carrier to block them.
So far, my Known hasn’t been breached, so I’m crossing my fingers I can avoid SMS spam for 38 days. I’ve got about 125 numbers I needed to block since they got through when I had filter unknown callers off (like when I need to accept a return call from AppleCare and spam leaks in) (My email accounts x RIP, spam city due to the election funding and drama llamas and sharing lists I presume). T-Mobile USA is doing an excellent job once I enabled their free block service for spam.