Ok, waaaaaay back when, I took an engineering class in college (insert your remarks about "they had colleges back then? here
) which a good portion of it was about ballistics. I actually enjoyed this part of the class.
At any rate, we were often tested to use the formulas to calculate the optimum muzzle velocity for a given round -- this was usually associated with an artillery or tank cannon round, but the process is the same. For instance, they would provide the caliber (say, 117mm) and the data for the round itself and we would have to calculate the best muzzle length in which to obtain the optimum muzzle velocity.
It would seem to me that these formulas and calculations were available to Sam Colt, et. al. back in the day and they utilized them. Of course, when you're engineering a new model pistol, you can also play with the charges, caliber, etc. to get something that you're looking for. And, other factors will also come into play. For instance, if you design such and such caliber, with such and such charge, the barrel thickness will need to be such and such in order to withstand the pressures. Thicker barrels will produce more weight which may not be optimum for a carry piece.
Then, let's not forget the idea of marketing to the actual user. I may want a shorter barreled pistol because of ease of carry or concealment and I'm willing to live with a lower muzzle velocity because of this trait.
Of course, it could also be the "whim" of the designer. I mean, why are the Colts, etc. 4 3/4" and Ruger had to have 4 5/8"? Is the 1/8" that much difference?
Inquiring minds and all that.....