Minecraft wiki entry for Spawn, associated text: are a passenger to another mob.
are riding a boat or a minecart.[7]
spawned as part of a generated structure.
have had something added to their inventory, including having something dispensed upon them (such as a saddle) or something they have picked up, but never for anything they spawn with. This includes dolphins playing with items[verify].
have been named with a name tag. However, one created from a renamed spawn egg does despawn as normal.
have had the NBT tag {PersistenceRequired: 1b} set on them, whether by being summoned with it, or by being set manually with /data merge or /data modify‌[JE only]. This is also the only way to prevent wandering traders from despawning.