Programmatically set the block visibility I set Configuration type to Block and selected my custom block to export the configuration from development/configuration/single/export. I got the following block visibility configuration.
visibility:
  _menu_position:
    id: _menu_position
    _menu_position:
      'main:menu_link_content:016650bb-ecd4-43e4-9d04-fef05ebcf186': 'main:menu_link_content:016650bb-ecd4-43e4-9d04-fef05ebcf186'
      'main:menu_link_content:2d195963-d98d-4f02-8129-6498c5db4b87': 'main:menu_link_content:2d195963-d98d-4f02-8129-6498c5db4b87'

For this, I have used the following function.
function placeBlock(EntityInterface $entity) {

    $config = \Drupal::configFactory();
    $settings = [
        'plugin' =&gt; '_block_module_block', // Set the plugin id
        'region' =&gt; 'header', // Set region to header
        'id' =&gt; $entity-&gt;id() . '-_bm_autoheader', // Use the page id and the module name for machine name
        'theme' =&gt; $config-&gt;get('system.theme')-&gt;get('default'),
        'label' =&gt; $entity-&gt;label(), // Use the page label
        'visibility' =&gt; [],
        'weight' =&gt; 0,
        'label_display' =&gt; 0, // disable label
        'page_id' =&gt; $entity-&gt;id(), // Reference page
    ];
    $values = [];
    foreach (['region', 'id', 'theme', 'plugin', 'weight', 'visibility'] as $key) {
        $values[$key] = $settings[$key];
        // Remove extra values that do not belong in the settings array.
        unset($settings[$key]);
    }
  
    foreach ($values['visibility'] as $id =&gt; $visibility) {
         $values['visibility'][$id]['id'] = $id;
    }

    $values['settings'] = $settings;
    $block = Block::create($values);
    $block-&gt;save();
}

In my case, $visibility gets a NULL value.
langcode: de
status: true
dependencies:
  module:
    - _block_module
  theme:
    - _drupal_theme
id: 57148-_bm_autoheader
theme: _drupal_theme
region: header
weight: 0
provider: null
plugin: _block_module_block
settings:
  id: _block_module_block
  label: 'Header Contact'
  provider: _block_module
  label_display: '0'
  page_id: '57148'
visibility: {  }

I need help to understand the block visibility setting. How does it work in Drupal 8? How can I programmatically set it?
Thanks in advance.
I have found the solution, set the visibility configuration by the following function using $menuLinkItem->uuid().


  function setVisibilityConfig($instance_id, array $configuration)


$block-&gt;setVisibilityConfig('_menu_position', array('id' =&gt; '_menu_position',
        '_menu_position'=&gt; [
              'main:menu_link_content:'.$menuLinkItem-&gt;uuid() =&gt; 'main:menu_link_content:'.$menuLinkItem-&gt;uuid()
            ],
        'negate' =&gt; null,
        )
    );


Thanks, @SumitMadan for helping out to understand the visibility concept.