Why can't you modify the query in a template page?
You can modify the query in a template page if you use pre_get_posts().
pre_get_posts()
The query can only be run inside the Loop.
According to WordPress best practices, the query should only be modified in functions.php.
functions.php
Due to execution order, the query has already run by the time a template is loaded.