When an elder guardian is spawned via spawn egg, it won't despawn or count towards the mob cap. This is inconsistent with other hostile mobs that are persistent in structures (except shulkers), including piglin brutes, evokers, vindicators, drowned, zombie villagers, and witches, which are persistent in their respective structures, but not elsewhere.
Linked issues
Comments 4
Why is this marked as related to MC-186596?
Confirmed. They don't despawn when spawned with spawn egg, but will despawn when using /summon.