Mobs nametagged should not despawn when swtiching to peaceful mode. Since 1.16 update they are despawning as soon as you set it to peaceful.
This is a problem on servers/realms since from time to time you need to switch to peaceful to clear the mob cap (otherwise mobs stop spawning).
It also happens with glass blocks, if you have a glass block 1 block above the floor you can just walk straight through it. 1.16.200