Set a specific page as 404 – not found via my own plugin

You can filter 404_template and return the path of your custom file from the plugin directory like this:

add_filter( 
    '404_template', 
    fn() => plugin_dir_path( __FILE__ ) . '404.php' 
);

This hook exists only when a 404 happens, so you don’t need any custom detection.