How to build an iron farm in Minecraft (26.x)
Rename a Name Tag on an Anvil and use it on the zombie so it never despawns.

A Name Tag gives a name to a mob. Named mobs show their name above their head and never despawn, which lets you keep a monster or a fish that would otherwise vanish once you move away.
It is made with the Crafting Table from Paper and Copper Nugget or Iron Nugget or Gold Nugget.
First rename the tag at an Anvil, then use it on a mob. The name appears when you look at the mob, and the mob stays in the world for good.
Craft it from Paper and a metal nugget (iron, copper or gold), or find it in chests and while fishing.
Copper Nugget / Iron Nugget / Gold Nugget + Paper → Name Tag
// Slots with several items cycle through every accepted option.
Rename a Name Tag on an Anvil and use it on the zombie so it never despawns.
It drops the items it carries, and keeps the name you gave it with a Name Tag.
A Name Tag on it stops it from despawning while you get your items ready.
At the Crafting Table: 1 × Paper and 1 × Copper Nugget or Iron Nugget or Gold Nugget give 1 × Name Tag. It can be found as loot in Mineshaft. Sold by Wandering Trader. Fishing: Fishing Rod.
It names a mob after being renamed at an anvil; named mobs never despawn.