Mobs can not move or attack when they are inside a closed trapdoor
Glitch works in Bedrock and Windows 10 Edition and when you close a trapdoor with the mob inside you can see that he can not move or even attack you
Players can normally move but the mobs can't
If you are in a single player world if you save and quit and rejoined again he will be free and go outside the trapdoor