How to set page/content title/header from a controller
You set the title in the route in the _title parameter:

mymodule.page:
  path: '/mymodule/page'
  defaults:
    _title: 'Page title'
    _controller: '\Drupal\mymodule\Controller\MyController::controller'


Or you can use a route callback:

mymodule.page:
  path: '/mymodule/page'
  defaults:
    _title_callback: '\Drupal\mymodule\Controller\MyController::title'
    _controller: '\Drupal\mymodule\Controller\MyController::controller'


And then put the title callback in the controller class, which receives the same parameters as the controller, so that you can determine a title on that information.