How to make custom page link to root automatically?

For the url to the root of the WordPress installation you can use:

<?php echo site_url(); ?>

see: https://codex.wordpress.org/Function_Reference/site_url

Edit: please check your url settings in the general WordPress settings.