Create a hierarchical taxonomy list in WordPress

You can use wp_list_categories() and pass in your custom taxonomy as an argument like so:

$args = array(
    'taxonomy'     => 'locations',
    'orderby'      => 'name',
    'hide_empty'   => false,
    'show_count'   => false,
    'pad_counts'   => false,
    'hierarchical' => true,
    'title_li'     => ''
);
?>

<ul>
    <?php wp_list_categories( $args ); ?>
</ul>

https://developer.wordpress.org/reference/functions/wp_list_categories/