Gates that close automatically using mechanisms or counterweights.
Option 1. Single.
After the gate is opened, it closes automatically after a while under the force of gravity acting on the counterweights.
Implementation:
"Corner post with mechanism." To build self-closing gates, "corner posts with mechanism" are used instead of corner posts. When preparing a gate with such a post, a second corner post with a mechanism is installed, and the gate built between them will automatically close after a certain time.
Option 2. A set of two gates.
Two gates are connected by a chain or rope through pulleys. Initially, one gate is open, the other closed. The mechanism and the length of the rope/chain are designed so that when one gate opens, the rope/chain tightens and pulls the other gate through the pulleys, closing it. Because of the pulleys, the direction in which the gates open is irrelevant.
Implementation:
A chain wall is built from corner posts with a mechanism from one gate to the other, forming a closed chain with two gates. Gates connected in this way will open and close alternately. When one gate opens, the other closes.
Option 3: A portcullis.
A system of two bars that raise and lower. A counterweight system is designed so that when one bar rises, the other lowers.
Implementation:
Instead of building a gate, propose building a portcullis. If the corner post is a standard one, it is raised and lowered manually. If the post is equipped with a mechanism, the same principle applies as options 1 and 2. If not connected to another gate or bar, the automatic gate closes after a certain amount of time. If connected to a closed chain, it rises or falls depending on the state of the object to which it is connected.