Granted, not all Roman camps had 3 or 4 gates, but my impression is that most of them did. So what for? Doesn't having that many weak spots defeat the purpose of the fortification? What was the pragmatic reasoning behind such decisions?
Early Roman fortress plans were not actually optimized for defense but for mobilization, and this is something we continue to see into the late Empire. Unlike a Castle, which is a stronghold that is retreated into during a raid or a war, Roman fortresses were much more like modern military camps as a logistical base and barracks for an active force, and a quarters for when the campaigning season was over.
So the reason for having typically 4 (and later more) gates? Mobilization. By having four gates your unit can clear out and get on the march more rapidly, and you have more pathways to efficiently manage supplies or the like coming in and out of the fort. But the main reason was mobilization. Have you ever seen that "good, we can attack in every direction" meme? That is exactly what early Roman forts were designed for. The Romans did not position their forces on the walls and throw spears and arrows down at their attackers. Their first plan of action was almost always to assemble the men, march out of the fort, form up in a battle line, and fight it out against the attacking army. The Principate Roman Army was a master of the set piece battle, and the Romans almost always won proper set piece battles. By having four gates, it was easy to rapidly mobilize your forces and march out to fight in any direction you wanted/needed to. It also facilitated flanking attacks if the enemy weren't attacking that part of the wall. We call this a "sally", where an army sallies out from its position to attack the enemy force. It was really, really common in the Roman period and for some parts of the middle ages.
That does not mean that Roman forts were useless for defense or the Romans did not use them for defense. When they knew they had the advantage, they preferred to go out to attack, and the fortress could provide covering and enfilading fire with torsion engines or whatever missile capability they may have had. During the early empire Roman forts exhibited the classic "playing card" shape, and were limited defensively. Walls were usually a stone face with a rubble core and an earthen ramp leading up the rear to the walkway. There were several reasons for that: one, it made rams effectively useless because they were battering a man-made hill, and two, it was because most Roman forts were built out of old marching camps which always piled earth from the trenches to make a simple palisade out of wooden stakes on an earthen mound, which then became part of the permanent fort's walls. It's probably also the reason why the towers are simply in-plane with the wall, rather than projecting, which is a rather significant flaw in the position of of towers in early Roman fortifications. Projecting towers allow for overlapping fields of fire in front of the wall, and early Roman fortresses for the most part lack that. In fact it's best to think of early Roman forts as really a permanent version of their typical marching camp, because that's what it was. It truly wasn't intended for being something that bogged down attacking armies in a siege. It was for taxing trade and monitoring immigration. It's very rare you see Roman armies actually attacking legionary fortresses in Civil wars until the 2nd Century AD because they preferred to fight on a battlefield instead of from a wall. It surely happened, but it usually wasn't notable.
Late Roman fortifications changed that, and were optimized for defense. They varied considerably in size and construction, and most of them were actually permanent replacements built on top of dismantled Principate (early Imperial) forts. Qasr Bashir in Jordan, for example, is a small facility for a small garrison, while others could still reach sizes capable of garrisoning 2000 or 3000 men, such as this reconstruction of El-Lejjun, one of the few larger facilities from the late Imperial period. As you can see, late Roman walls were typically several meters taller, and they utilized projecting towers usually with curved faces (which made them harder to knock down). Overall, Roman frontier policy hadn't changed much. Their primary purpose was an operations and logistics base for a small unit which patrolled the frontier, taxed trade, and managed migration. But with the increased organization of peoples on the Roman frontier, resulting in larger raiding and "invading" forces, and an increasing reluctance to engage in set piece battles due to the potential cost of possibly losing the battle, a more versatile strategy was employed which included wearing the enemy out by attrition during long sieges, or holing up and allowing them to pass through and then harassing their supply and communication lines behind them, or blocking off their path of retreat entirely. Most Roman cities also had walls built in the 3rd century, and of course there were cities like Rome with its towering Aurelian Walls, too high for ladders and too thick to be countermined, or the even more impressive Theodosian Walls of Constantinople, which were outright impossible to countermine due to the depth of their foundations and the width of the walls, and which also had multiple layers of defense to protect the capital. And this brings me to my final point, which was that even though the Romans changed strategy, they simply became more versatile and didn't totally abandon earlier practices. Late Roman fortifications had just as many primary gatehouses as early Roman fortifications, primarily for mobilizing armies and wagon trains as these forts served as supply bases when the Romans needed to campaign across the border and shift some "tribes" around (yeah the Romans literally moved entire peoples, long explanation short). But the towers also typically had smaller gatehouses called "postern gates" on the side, which were purely for the purpose of sallying out to attack the besiegers or destroy their siege equipment, and then retreating back in. The Romans usually didn't send their entire force out to fight a set piece battle anymore, but such things still happened, such as at the Siege of Amida in 359 where multiple times some of the few thousand defenders marched out and fought the Persians, destroyed their siege equipment, or attempted to attack them in their camp. These gatehouses facilitated versatility in the Roman strategy, which was evidently worth the trade off of a potential "weak point" in the wall.
Sources:
If you want to get comprehensively into Roman frontiers, however, I strongly recommend:
A lot of people recommend Luttwak's The Grand Strategy of the Roman Empire but Luttwak's thesis was pretty flawed (his Grand Strategy of the Byzantine Empire was just flat out wrong), and he's very outdated now.