Automatically add class-attribute to gallery?

If you take a look at native galleries they already have IDs with counter implemented:

$instance++;
...
$selector = "gallery-{$instance}";
...
$gallery_div = "<div id='$selector'class="gallery...

So first gallery within a post will have <div id="gallery-1"... and so on. This is used by core itself to target different styles at each instance.

If you need to do something more custom you can use gallery_style filter, which gets passed those styles and opening div markup, to similarly keep track of instances and inject your custom classes as necessary.