LOL, you fought against H or even VH difficulty don't you? and bet you didn't have government inside your town, or your government has no / bad security sense..... Actually, the AI uses spy exstensively, and remember : YOU DIDN'T GET ANY MESSAGE IF A SPY INFILTRATE YOUR SETTLEMENTS, you get the message if he was either killed or expelled, that's why your settlement's gate will be opened... (ai spy often get very good subterfuge)