In MC they had several mechanics to prevent the player from access.
1) Story related. After Vaati's initial attack on the castle and the release of the monsters, the Carpenters were blocking the player from entering Castle town again. After the first dungeon the Carpenters also force Link to go by South Hyrule Field again, instead of Lon Lon Ranch.
2) Moving blocking guards. Just like in MM the guards remain in front of the gate, but as Link approaches they keep in the direct line of Link and the gate.
3) Invisible pull back trigger. When Link crosses a certain line with the gate a person or something else calls Link back and the game takes over, walks Link back to a save distance and gives back control.
4) Natural obstacles. Link needs to acquire the necessary items first before he can pass those.
Then you can also make a gate like those in found in parking garages and privately owned properties. You know like the ones with a booth and a pole