Which era are we talking about?
For me, it's highly dependent on the level of defenses my cities have. If we're talking the Ancient Era with no walls, then yeah, a ranged unit per city and a few spare non-ranged units is nice, otherwise barbarians can be a major pain. Even with level one walls, having a unit to finish off the barbarians more quickly is nice.
Once we get to medieval or renaissance walls, or the level 400 defenses in each city? If I have 10-12 cities and no plans to attack, I don't know, I might keep about four units around? More if I have old ones that can sit around for low maintenance, and/or have the civic that enables them to act as military police and increase happiness, but just enough to launch a counter-attack would seem sufficient to me as a standing force.
Why not more? It's a waste of shields and money. Units are expensive in Civ VI, better to spend that on building up the economy. They also cost money to maintain, after the earliest units. So you either spend your shields on units and spend your money supporting them, or you spend your shields on commercial districts, don't spend your money on units, and have even more money. Or invest in science or production or culture. Either way, build or rush a couple of units at the relevant border zone, and you've probably saved money overall, and have certainly saved shields, giving yourself a stronger economy.
But why build walls? They cost shields, yes, but don't cost maintenance. Certain governments also have bonuses from them, and there's a civic that gives half off their cost, which can make them a cheap form of deterrence compared to units. And even with basic walls, the city gets ranged bombard, which is essentially a ranged unit. Thus I've found them to be a good way to ensure I don't have major concerns at the border, while also not spending much.
However, I'm also not playing Diety... things may change there.