Force redirect not logged in user to (wp-login.php or wp-admin) for specific page

The template redirect is most useful for managing the output of theme files. To redirect a non-logged in user when the page loads, attach your function to the ‘init’ hook. (If you call it sooner than that in the stack, you may get an error because the function definition hasn’t been included yet.)

In short, if you replace the action hook in the code you provided with:

add_action( 'init', 'my_page_template_redirect' );

it should achieve what you’re trying to accomplish.

Reference: https://developer.wordpress.org/reference/functions/is_user_logged_in/