This happened to me a while ago, but I never thought to post it on here.
I was in Solitude, doing some Thieves' Guild stuff, being the badass Dovahkiin I am, and as I'm up on a ledge, I see a winged shape far off in the sky. A dragon. "Odd, I've never seen them this close to a city," I'm thinking. It flies closer and closer and ohTalositsattackingme! Eventually I kill it, and only after I kill it I start to remember I'm within the threshold of a large city where you have to go through a gate to enter. This has never happened to me before in Skyrim, and I assumed it could never happen. But since then, it's happened twice. Once in Windhelm, and once in Whiterun.
Has this ever happened to any of you? Is it just a glitch, or is it supposed to happen?