Even better, just get an app that puts everybody who is not a contact right in voicemail. I don't know why this is not a built-in open on iOS and Android. If you're expecting a call from a non-contact just turn it off for 15 minutes or call them back.
Do Not Disturb mode on more recent Androids (and I believe iOS too) effectively does this. I configured my phone to just not even ring for non-contacts, so I only see it if I have my phone open already. Otherwise I only find out when I see a voicemail later. It's been on for 3 months and I think 1 has been legitimate.
As an implementation of Do Not Disturb, that sounds like the expected and correct behaviour. It is only lacking if you want to (ab)use DND as a technical solution to the social problem that there is no adequate legal protection against spam calls in your jurisdiction. In Europe, I get a spam call maybe once a month, slightly more if you see legitimate (according to the local interpretation of law) market research and opinion polling as spam.
I'm overusing it for the permanent spam-blocking use case, for sure, but it makes sense to me that often when I say "Do Not Disturb", I mean specific groups. My spouse and kids can interrupt me pretty much whenever they want (especially if they know why I don't want to be disturbed - then they can make an educated judgment about if it's worth it or if emailing me is better). Maybe I don't want to be annoyed but I'm on call, so work contacts can get through. If anything more granularity and "contact groups" would be nice.
I've been wondering the same, I recently made MyHumans for iPhone to do just this. I think this works for a lot of people, and it has completely solved my spam problem.