All instances of block are not getting removed This question is a continuation of this Block in Drupal 8, The second problem I am facing is that suppose I select block made for comment section and place it under Sidebar second section and afterwards deselect comment from configuration setting then after clearing cache the label for comment from block section is removed but block placed under Sidebar section still remains with default message for broken blocks "This block is broken or missing. You may be missing content or you might need to enable the original module.".What changes should I make so that this message is removed ? Thanks.
As mentioned in the other question, what you need to do is query for the blocks that no longer exist and delete them.

BlockContent::delete()/getInstances() is an example for that. You can do a similar query, either by using entity_load_by_properties() for the plugin ID that those blocks would have. Or you can run an entity query, which has more options.

You don't have an entity, so in your submit, you need to build a list of all unchecked options and then query for those. The advantage of doing an entity query is that you can do an IN condition, so you probably want to use that.

A more complicated example, that looks at settings and either updates or deletes the affected blocks can be found in simplenews.module's Newsletter::postDelete():

if (\Drupal::moduleHandler()-&gt;moduleExists('block')) {
  // Make sure there are no active blocks for these newsletters.
  $ids = \Drupal::entityQuery('block')
    -&gt;condition('plugin', 'simplenews_subscription_block')
    -&gt;condition('settings.newsletters.*', array_keys($entities), 'IN')
    -&gt;execute();
  if ($ids) {
    $blocks = Block::loadMultiple($ids);
    foreach ($blocks as $block) {
      $settings = $block-&gt;get('settings');
      foreach ($entities as $newsletter) {
        if (in_array($newsletter-&gt;id(), $settings['newsletters'])) {
          unset($settings['newsletters'][array_search($newsletter-&gt;id(), $settings['newsletters'])]);
        }
      }
      // If there are no enabled newsletters left, delete the block.
      if (empty($settings['newsletters'])) {
        $block-&gt;delete();
      }
      else {
        // otherwise, update the settings and save.
        $block-&gt;set('settings', $settings);
        $block-&gt;save();
      }
    }
  }
}