The Minecraft wiki says this about iron golem spawning:
Since Java Edition 1.14, an iron golem spawns based on villager gossip at a gathering point. The villager who starts the gossip must have a profession that is not nitwit, slept in the last 24000 ticks, been to their job site block in the last 36000 ticks, gossiped 5 times about the need for an iron golem, and have four other villagers within 80 blocks. The Iron Golem then has a chance to spawn in a 16×6×16 area centered on the location of the villager who spread the gossip.
Unfortunately, this says nothing about where the iron golem can or can't spawn. I'm trying to make an iron farm, and a trading system, and I would rather not remove the blocks, but make them spawn proof instead.