I was in Salzburg back in 95 with a HS exchange program. We were traveling around and having a great time. That day we went up to the castle kinda near closing time. The entry booth was unmanned so our group walked on in.
We walked around, saw lots of the castle and the views over the city were enchanting. Most of our group left, but about six of us were still in the castle later. It turns out they close and lock the main gates once all of the tourists are out. Since we didn't get tickets in, we apparently went uncounted and got locked inside.
On my my buddies came running up to me as I was sitting on a battlement being morose (summer fling issues) and declared with alarm "we're locked in!" so I jogged to the gate with him.
This is pre cell phone and we weren't great at German. I told him to rally the rest of our stragglers and stood by the gate to think of how to get out. As the group was walking down the path to me, I heard keys jangling outside the gate.
After a moment the smaller postern door opened. Standing outside was a kid about 13 years old with a sack of groceries. I said entschuldigung and blocked the door open. Our group all piled out through the gate and ran off down the road while the kid just stood there looking shocked.
That was the first time I accidentally got locked in a castle in Europe. They're remarkably effective at keeping people both in and out, both are issues I've had to deal with at various times.