I don't have the absolute truth about this (or anything else
), but i think the garrison thing works more or less like this:
When the enemy enters a region witha a walled city the game makes a roll for each level of the city fortress. Each suscessfull roll will generate a garrison unit inside the fortress.
For my experience, i think this roll is modified somehow by the loyalty of the region, so a catholic region will generate garrisons against protestant invaders in a more dependable way than a region with high protestant loyalty.
If no roll is suscessfull, the city will generate no garrison and "open the gates" to the invasor, who will get control of it inmediately.
So, cities with high loyalty to your side and/or high level fortress are usually able to generate some garrison and force the enemy to siege. But you can never be sure.
If you want to keep a walled town the surest way is to put one of your units inside as a garrison. This way, even if all the rolls fail, taht unit will defend the city and it will not open the gates and you will force the enemy to siege the city.
I usually use weak units for this, like light infantry, one element cavalry etc, as they will avoid the "open gates" as good as any other stronger units.