The mechanic
Villagers that see a hostile mob (or a zombie villager) panic and try to summon an iron golem — provided each villager has slept in the last day, the area has not recently spawned a golem, and there is spawn space. Farms stack this: villagers in pods, a zombified piglin or zombie in a minecart as the scarecrow, and a water stream pushing the golem into lava or a crusher.
The simplest survival design
Three sleeping villagers, one scarecrow, a spawn platform of 5×5 blocks, and water channels to a lava blade plus hoppers into a chest. Expect roughly one golem every 30–60 seconds when it works — each golem drops 3–5 iron ingots. That is 200+ iron per hour, enough to quit mining iron entirely.
Why farms break
The usual culprits: a villager cannot reach or will not sleep (bed blocked), the scarecrow is visible to players and gets killed, spawn spaces are blocked by carpet or slabs, or the farm is too close to your village so golems spawn there instead. Fix sleep first — it is the requirement most often missed.