Minecraft wiki entry for Pillager_Outpost, associated text: Iron golems and allays spawn only during the generation of the outpost structures. If an iron golem or an allay spawns, it does so only inside a cage.‌[upcoming: JE 1.19 & BE 1.19.0] Pillagers do not attack iron golems in cages, although the iron golem can attack any pillagers that are one block near the cage, because iron golems can attack through a one-block wall.