Category tags with comma’s

In this line:

$cats .= $category->name . ', ';

You append a name of category to variable called $cats.

But you never reset this variable. So every post appends its categories to the same variable.

So here’s how to fix this:

<?php
  $categories = get_the_terms($custom_args->ID, 'veranstaltungen-category');
  $cats=""; // set empty string as  value

  foreach ($categories as $category) {
        $cats .= $category->name . ', ';
        echo rtrim($cats, ', ');
  }
?>

Of course you can also add commas to your second code:

foreach ($categories as $i => $category) {
         if ( $i ) echo ', ';
         echo '<span>'.$category->name .'</span>';
}