You can do this with Yoast SEO plugin. Basically, afterAfter you installedinstall the plugin, just go to Yoast SEO > Search Appearance > Content Types.:
Yoast SEO > Search Appearance > Content Types
Find your custom post type, then select "Off" on "Show [your_custom_post_type] in search results?". You can do this for each post type.
But I don't think it is recommanded to redirect to a 401 page. It could negatively impact your website's SEO. Otherwise, you can redirect to example.com.
Hope it helps!