It's happened to me twice now, in Riften and in Markarth. I have no bounty in either place (or at all - I play a goodie-type) and suddenly a bunch of guards run up and start attacking me. Not all the city guards, just some of them. They didn't give me the chance to yield (I was unarmed anyway) or try to arrest me, no dialogue.
The time it happened in Riften I reloaded an earlier save and that sorted it. This time, I got annoyed and killed the guard that attacked me in the temple of Dibella (no, I wasn't stealing the statue) and after that they're all ok with me again. AI?? Hah...
