Minecraft wiki entry for Shulker, associated text: When the shulker gets hit and then has less than half its health remaining, it can teleport without spawning a new shulker. The chance for this to happen is 25%. It uses the same process as described below. If the attempt fails, it continues with the spawn attempt.
The hit shulker must have its lid open.
The hit shulker needs to find somewhere to teleport. For this, it takes a random block in a 17×17×17 cuboid centered on the shulker and then checks if the block has a valid face to teleport to. If not it proceeds to try this up to 4 more times. If no valid face is found, the attempt fails.
Each other shulker within 8 blocks of the hit shulker decreases the odds of success by 20%. When five or more other shulkers are nearby, no shulkers will spawn, but the hit shulker still teleports.