Hostile mobs despawn in a few minutes (sometimes seconds), when they are not in direct sight of the player. Even if the player touch them or trap them, they despawn. This change appeared after last official update and it messed up hostile mobs mechanics. For example - It is not possible to keep them in the trap together in "herd" to get more heads with charged creeper explosion (they despawn sooner than I am able to bring some creeper). Please do something with hostile mob mechanics to keep the game playable...
Related issues
Comments

All non-persistent mobs will despawn at a certain distance from the player.
Incorrect despawning of persistent mobs is tracked in MCPE-21416.