How to get get_categories()’s ‘hide_empty’ argument to work with global year var in the archive template?

Why not add an if statement to check whether $count > 0 before printing your <li> on line 13:

<?php if($count > 0): ?>
    <li><a class="name" href="https://wordpress.stackexchange.com/questions/237988/?cat=<?=$category->term_id?>&year=<?=$_GET["m']?>"><?=$category->name?> (<?=$count?>)</a></li>
<?php endif; ?>