How to programmatically add custom markup to every displayed user name
Seems hook_user_format_name_alter() is your best bet. But same as in the other answer markup doesn't seem to be allowed everywhere. Normally the user name is only allowed to be a string.

The following won't work for Views for example. It will print just a string. 

use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
 * Implements hook_user_format_name_alter().
 */
function MYMODULE_user_format_name_alter(&amp;$name, $account) {

  $name = new TranslatableMarkup('@name &lt;span class="foo-bar"&gt;Foo Bar&lt;/span&gt;', ['@name' =&gt; $name]);
}

/**
 * Implements hook_preprocess_HOOK().
 */
function MYMODULE_preprocess_page_title(&amp;$variables) {

  if (\Drupal::routeMatch()-&gt;getRouteName() == 'entity.user.canonical') {

    $name = $variables['title']['#markup']-&gt;__toString();
    $variables['title'] = new TranslatableMarkup('@name &lt;span class="foo-bar"&gt;Foo Bar&lt;/span&gt;', ['@name' =&gt; $name]);
  }
}


So, what I'd recommend now is, you maybe take the *_preprocess_page_title hook – as this is working just fine on user pages – and for all other places (references, Views etc.) you maybe create a new custom formatter or pseudo field to do the job.