How to attach a library to a page controller that returns a plain Symfony response?
After rendering of $build the attachments have bubbled up to $build['#attached'] and you can add them to a response, which implements AttachmentsInterface, for example an HtmlResponse:

$html = \Drupal::service('renderer')-&gt;renderRoot($build);
$response = new HtmlResponse();
$response-&gt;setContent($html);
$response-&gt;setAttachments($build['#attached']);
return $response;


To place the libraries on the page you have to enclose the page in an html render element

$build = [
  '#type' =&gt; 'html',
  'page' =&gt; [
     // content with attached libraries  
  ],
];


or implement the placeholders where the attachment will end up in a custom template, see template_preprocess_html().