I think you might've missed that I said the margin-top can be safely removed because it is ineffective. It isn't "increasing" the visible whitespace between sections, because all block level elements already have sufficient *bottom* margin. And browsers collapse/merge the top margin of the next element with the bottom margin of the previous element.

No matter whether it's a paragraph, list, <pre>, gallery or <table>, their bottom margin is already taking care of that space. When I removed the top-margin of headings locally it made little to no visible difference.

So if the goal was to increase the space between sections, it failed to do that.

If we do want to increase space between sections, I suggest it is implemented in different way. Using margin-top for that is in my opinion inappropriate and bound to cause layout hazards.

I agree the specific instance in which I ran into this bug is dubious, but in general you mustn't assume that a heading will only be used in the root flow of the content and only in the n+1th section of page.

Using margin-top means that:
* Using the heading in the first section on a page will cause a weird gap on top because it's trying to offset itself from the previous section when in fact that is the top of the page. Which is a problem since content wrappers already have padding, and that doesn't merge with margins of elements inside.

* Using the heading inside another element (blockquote, table, infobox, form), even inside elements that aren't intended as their own block (e.g. heading bubbles such as on [1]) will now have a margin on top on the inside intended to separate itself from a section. This could in theory be worked around by resetting margins or creating negative catch margins. However that would be an unintuitive hack that doesn't scale because it's moving the responsibility to the wrong component (e.g. if you want to use a <table> on a page, you cannot be expected to have to set all kinds of inline styles to make it render properly, it is the skin's fault for changing the default of all headings to act like section separators. The skin should take care to recognise the relevant headings and style them and leave the others untouched).

I'm not going to spend time on finding one of many alternate ways to implement section separation margins on desktop, but the way it is implemented right now is and will continue to cause all kinds of layout problems due to it applying top-margins that are too large when applied in a context that isn't between two sections.

[1] https://www.mediawiki.org/w/index.php?title=Help:VisualEditor/User_guide&oldid=984581#toc)