how do 404 pages work?
For the configured custom path:

CustomPageExceptionHtmlSubscriber::on404

   public function on404(GetResponseForExceptionEvent $event) {
    $custom_404_path = $this-&gt;configFactory-&gt;get('system.site')-&gt;get('page.404');
    if (!empty($custom_404_path)) {
      $this-&gt;makeSubrequestToCustomPath($event, $custom_404_path, Response::HTTP_NOT_FOUND);
    }
  }


If no custom path is configured the subrequest is built for '/system/404' pointing to the controller you've mentioned:

DefaultExceptionHtmlSubscriber::on404

  public function on404(GetResponseForExceptionEvent $event) {
    $this-&gt;makeSubrequest($event, '/system/404', Response::HTTP_NOT_FOUND);
  }


To customize other status codes than 403 or 404 extend DefaultExceptionHtmlSubscriber and override on4xx().