get_query_vars always retruns empty value

In my test scenario I use the original twentytwentyone theme with no
plugins activated. My code is placed at the end of functions.php.

This is the problem. Your code is running as soon as functions.php is loaded, which is before the query vars are populated. If you use get_query_var() inside an action hook that runs later, or inside a block or shortcode, it should work fine.