There are Android apps that block calls from non-contact numbers. Including open-source apps on GitHub. Maybe there are such apps for iOS also? It baffles me that this functionality isn't built-in.
edit: Nevermind I can block non-contact calls in Do Not Disturb mode in the LG phone I'm using: https://i.imgur.com/ZcRSXlK.png Maybe iOS DnD has this too?