Name Tag is an item that makes a mob permanent. A named mob never despawns, so a Name Tag is what turns the zombie powering your experience farm, a llama cut loose from a wandering trader or any other mob the game would quietly delete into something that stays put for the life of the world.
Using one is a two-step job, and the second step is where people get stuck: the tag does nothing until you rename the tag itself on an anvil, which costs a level and some experience. Only then does using it on a mob apply that name, consuming the tag. It works on almost anything alive — a dog, a horse, a villager, even a hostile mob you want to keep around — but not on the ender dragon and not on a player.
Tags are crafted from paper and a metal nugget, or found. They turn up in dungeon and mineshaft chests, come up as treasure while fishing, and wandering traders sell them.
The name tag easter eggs are real mechanics rather than cosmetics, and a couple of them are genuinely useful. A mob called Dinnerbone or Grumm renders upside down. A sheep called jeb_ cycles through every wool color for as long as it lives. A rabbit called Toast wears a memorial skin. The one real name tag trick is Johnny: a vindicator given that name attacks every mob it can reach — you included, sparing only its fellow illagers — so a captured raider becomes a weapon that needs a wall between the two of you.