How to manipulate wordpress template tags’ output

For lots of WordPress template tags, including the_categories() you can’t change the HTML output. Instead, you can use something like get_the_categories() and loop through the results to create your own HTML.

<ul id="whatever" data-attribute="you" class="want">
<?php
    $categories = get_the_category();
    if ( ! empty( $categories ) ) :
        foreach( $categories as $category ) :
?>
            <li><a href="https://wordpress.stackexchange.com/questions/208347/<?php echo esc_url( get_category_link( $category->term_id ) ); ?>" alt="<?php echo esc_attr( sprintf( __( 'View all posts in %s', 'textdomain' ), $category->name ) ); ?>"><?php echo esc_html( $category->name ); ?></a></li>
<?php
        endforeach;
    endif;
?>
</ul>

The above version uses some standard WP methods to clean up the output of each bit being printed (esc_url, esc_html…). A more straightforward, if potentially risky, method could look something like this within the foreach (depending on your permalink structure):

echo '<li><a href="https://wordpress.stackexchange.com/" . $category->taxonomy . "https://wordpress.stackexchange.com/" . $category->category_nicename. '">' . $category->cat_name . '</a></li>';