This is probably not the template for a category archive, but for a custom page template because of this:
/*
Template Name: Categories
*/
The query variable ‘cat’ is not set in pages.
Move get_category_link( $id );
inside the foreach.
<li><a href="https://wordpress.stackexchange.com/questions/151716/<?php echo esc_url( get_category_link( $cat->term_id ) ); ?>"><?php echo $cat->name; ?></a></li>