But the torpedo launchers on the NX-01 Enterprise were only a couple of meters long
...And fired sublight projectiles as far as we can tell (IIRC, the few warp firings involved the launcher in the rear pod, of unknown length, and aft firing at warp might not require acceleration to begin with). Perhaps the barrel is related to the warp acceleration ability observed with, say, the E-D launcher?
Similarly, the long barrel might be unnecessary for most of the DS9 launchers, and perhaps only present in the original weapon sail units if at all.
the TOS 1701 ones were probably smaller
...Unless tilted. After all, the Voyager
ones would appear to be canted down quite a bit, or else the shots would not clear the primary hull.