how to display a widget only on a page where the custom field is defined?

If you have a custom field (metadata) attached to a particular post, page or custom post type, you can do something like the following in your page template file:

Example example-template-file.php

<?php 

    $sidebar_id           = 'my-custom-sidebar-id';
    $my_custom_meta_value = get_post_meta(get_the_ID(), 'my_custom_meta_key', true);

    if ( !empty($my_custom_meta_value) && is_active_sidebar($sidebar_id) ) {

        dynamic_sidebar($sidebar_id);

    }

?>

Notes: dynamic_sidebar, is_active_sidebar