I wrote 'most of the time' because often they go for the city which is the nearest to their borders. I think the AIs tend to calculate the odds before taking a decision. If the border city is too well defended, they'll ignore it.
My personnal example (the one that springs to my mind) is a border city with ten well promoted units in it, and another city 4 tiles southward with one unit defending it. They aimed right to this city, ignoring the well defended one. I must say the other city was surrounded by mountains, and they couldn't have scouted it.
You must not think I hate this game because the AI knows stuff she should not, I think it is a part of it, and a necessary evil to render the AI at least equivalent to, err, a parrot.
So a basic trick is to leave equivalent but very mobile garrisons (which can regroup in the attacked city in one turn) in your cities, so that the AIs will aim for the closest one. Et hop ! You know were their attacks will land. It's magic ! (you can also leave big stacks wandering in the country, as they don't seem to be taken in account)