Alter contextual links
The correct way to alter contextual links is to use hook_contextual_links_alter.

In your case, it should look something like:

function my_module_contextual_links_alter(array &amp;$links, $group, array $route_parameters) {
  if ($group === 'block') {
    // Hide Configure Block option.
    unset($links['entity.block.edit_form']);
  }
}


The contextual links are heavily cached in the browser, therefore you need to make sure that the browser session cache is cleared - window.sessionStorage.clear(); - source.