How to add nonce tag to inline script for CSP

You can use the script_loader_tag filter:

function wpse_406351_script_tag_nonce( $tag, $handle ) {
    if ( $handle === 'id_of_script' /* handle used in wp_enqueue_script/wp_register_script */ ) {
        $nonce = wp_create_nonce(); // Or whatever your nonce value should be

        $tag = str_replace( '<script ', "<script nonce="$nonce" ", $tag );
    }

    return $tag;
}

add_filter( 'script_loader_tag', 'wpse_406351_script_tag_nonce', 10, 2 );