Iron golems will occasionally attack the player after they have switched to creative/spectator mode by using F3+N, they will also follow the player and still occasionally attack them.
- Attack a villager near the golem
- If the golem sees you, do F3+N
- The iron golem will follow the player in creative/spectator and will swing their arms.
Note: It is required to attack villagers until the golem is hostile, because attacking the golem rather than the villagers will not trigger the bug.