The following is based on a decompiled version of Minecraft 1.9 using MCP 9.24 beta.
When a chunk gets unloaded the entity in the chunk are added to the list net.minecraft.world.World.unloadedEntityList. When all entities are updated this list is cleared and the entities are removed from the list of loaded entities.
The problem is that commands are executed after a chunk is unloaded, but before the entities are unloaded:
This causes bugs like
MC-96131 where a chunk is unloaded, a command (or possibly something else as well) loads the chunk, the entities are not removed and their data becomes reset.