I think it's mostly ease of handling. Shorter barrels weigh less and are much easier to use in tight spaces. In modern rifles they're less accurate, but not at the ranges infantry use them. With the shotgun i imagine choke is at least as important as barrel length.
Short wide barrels for combatting longer rage drone air targets. Longer distance barrels for "sensitive" defense UwU
I think it's mostly ease of handling. Shorter barrels weigh less and are much easier to use in tight spaces. In modern rifles they're less accurate, but not at the ranges infantry use them. With the shotgun i imagine choke is at least as important as barrel length.