Barrels renamed in an anvil lose their custom name when broken and picked up again. Other storage containers, like chests and dispensers, keep their custom name when they are broken and picked up again.
To reproduce (in survival):
- Take a barrel and rename it in an anvil.
- Place it down and open it to check that its custom name is on top of its inventory.
- Break it again with an axe and pick it up.
- You'll notice that the barrel lost its custom name.