Sounds like you've got an enemy spy working within your city. When you/computer put a spy in a city, they have a certain % of chance of opening the gates when/if your army attacks it.
For governors, you'll just need to adopt new people when they come along and make sure, when you get the chance, marry your people off ASAP. I don't think there's any other way.
Bookmarks