The line https://github.com/wikimedia/mediawiki/blob/master/resources/src/mediawiki.skinning/content.media-common.less#L10 added a margin reset in https://github.com/wikimedia/mediawiki/commit/b530667b250cec009532736b147f60bfd887f37d with a comment " Maybe belongs in element.css for figure"
This does actually belong in the normalize module which applies to all skins. Apparently editors are having to work around this for on-wiki styles so this should be upstreamed to normalize.less