How to include a query_vars value in document_title_parts?

If your query var tags is registered properly then the following code snippet will definitely work, I’ve tested it. It’s a modified version of your code snippet. Please make sure to add the code to your functions.php file.

function prefix_custom_title($title_parts) {
    global $wp_query;
    if (isset($wp_query->query_vars['tags'])) {
        $title_parts['title'] = $wp_query->query_vars['tags'];
    }
    return $title_parts;
}
add_filter( 'document_title_parts', 'prefix_custom_title' );