Printing fieldable panel pane custom field in template properly
Ignoring the empty field-labels was a problem! The issue was with those field labels, which were generated by the Fences module. They were somehow causing the h2 to close too early.

I ended up modifying the module myself, so that the template checks if a field label exists before adding it to the DOM.

I also ended up finding an issue on the module's issue page which has a patch to fix it directly, in case anyone is interested: https://www.drupal.org/node/2605808