Attaching libraries in modules
The ShortcodeBase Class uses renderplain which strips 'the attached assets and cache tags'

In the comments to the source code they say: We use renderplain so that the shortcode's cache tags would not bubble up to the parent and affect cacheability. Shortcode should be part of contentand self-container.

In order to attach the library I then rendered the Array with this code: 

$renderer = \Drupal::service('renderer');
return $renderer-&gt;render($output);


and it works. Need to understand if and how it affects cache, though.