Use the selected
HTML attribute. See w3schools docs.
In your foreach loop, check if the current category matches the current iteration, and add the selected
attribute to that option
element. You are already getting the ID of each term, so you’ll need to also get the current category ID so you can check against it. Perhaps I would use get_the_category, to get the current category.
EDIT: Here is your updated function. New lines are commented:
function hierarchical_category_tree( $cat ) {
// grab the current category object
$current = get_the_category();
$next = get_categories('hide_empty=false&orderby=name&order=ASC&parent=" . $cat);
if( $next ) {
foreach( $next as $cat ) {
echo "<option value="' . get_category_link( $cat->term_id ) . '"';
// if the current category object matches the current ID of the iteration
// add the selected attribute to the option element
if ($current[0]->term_id == $cat->term_id) {
echo 'selected';
}
echo '>' . $cat->name . '</option>';
hierarchical_category_tree( $cat->term_id );
}
}
echo "\n";
}