Think the problem is following
$tax_name = $taxonomy->name;
....
$new_rules[$ancestors . '(' . $term->slug . ')' . $suffix . '/?$'] = 'index.php?' . $tax_name . '=$matches[1]';
so that for category $tax_name = ‘category’, and this varible is used as query_var, which should be “category_name” for category.