Enemies in the Zelda games tend to use a line-of-sight approach to their attacks. Line of sight often seems to be based on what obstacles their attacks can clear, not just what they can walk over.
At least for trolls, even once you have stepped out of their line of sight they will continue to move toward you for a bit. As far as I can tell, if you remain out of their line of sight for long enough AND if you are more than two or three tiles away from them, then they'll leave you alone and continue meandering aimlessly about the room until they spot you again, but I think if you're within two or three tiles, they'll still try to move toward you even if there's a wall there. At least they'll try for longer before giving up and leaving you alone.