How to get dynamic template-function generated CSS into HEAD?

If you use wp_enqueue_style(), with your function, you could call the function from the page (single.php etc.) … pass a string through with the page name, use that in the function to decide which style you are enqueuing. This will then load the script in the head in the correct manner.

https://developer.wordpress.org/reference/functions/wp_enqueue_style/

Eg.

// In single.php
enqueue_my_script('single');

//In functions.php
function enqueue_my_script($page = null){
    if($page === 'single') {
         add_action( 'wp_enqueue_scripts', 'single_styles');
    }
 }

 function single_styles() {
      wp_enqueue_style( 'slider', get_template_directory_uri() . '/css/slider.css', array(), null, null);
 }

I’m pretty sure something like that should work how you want it to, though it is nearly 2am for me!