How do I place a block in a region, programatically?
You can try this, create an instance of a block plugin on the fly for the block content:

$block_content = \Drupal::entityTypeManager()-&gt;getStorage('block_content')-&gt;load(12);

$plugin_id = 'block_content:' . $block_content-&gt;uuid();
$block_view = \Drupal::service('plugin.manager.block')
  -&gt;createInstance($plugin_id, [])
  -&gt;build();

$variables['page']['content_right']['custom_block'] = $block_view;


But it's better to configure the block plugin in UI and build the configured block instead. For more info see this question Programatically render a block in a twig template