The reason for the bug is that the Iron Golem has a custom checkSpawnObstruction function which also checks for an opaque block below, which is inconsistent with all other usage of the function, as it is only supposed to check for obstruction.
@Edvinas Katkus For what I was doing I needed to replace only air (and keep surrounding blocks) the empty "~" were just an example, for what I was making I was using larger areas.
Is this not a dupe of MC-94225?