If you look at the gallery shortcode function the opening div (to match that closer you’re missing) looks like this:
$gallery_div = "<div id='$selector' class="gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}">";
then this filter is run
$output = apply_filters( 'gallery_style', $gallery_style . $gallery_div );
More than likely there’s code somewhere in your theme or a plugin that’s messing with the gallery_style
filter and that’s your culprit.
Here’s the proper way to remove the gallery styles. Directly above the previous code is this:
/**
* Filters whether to print default gallery styles.
*
* @since 3.1.0
*
* @param bool $print Whether to print default gallery styles.
* Defaults to false if the theme supports HTML5 galleries.
* Otherwise, defaults to true.
*/
if ( apply_filters( 'use_default_gallery_style', ! $html5 ) ) {
$gallery_style = "
So you just need to force that filter to return false, like so:
add_filter( 'use_default_gallery_style', '__return_false');
then get rid of the filter function your theme is adding that wipes out the styles and the opening div.