The barrel length doesn't play into the accuracy equation all that much, as long as it's within acceptable limits.
Regardless of barrel length, the "fit" of the projectile to the inside of the barrel matters a ton, and not all barrels are equal. A short barrel can easily prove more accurate than a long barrel. Another deciding factor is the overall length of the cartridge, and how close the bullet sits to the back of the rifling.
Cartridges are purposely sized a bit "small" so that they're sure to fit in the variably-sized chambers (due to tolerances, and often differing manufacturers) they're designed for. As a result, two things happen. First, the cartridge sits tipped "nose-down" a bit, resulting in it hitting the rear of the rifling at an angle, deforming the projectile. Second, the projectile actually moves forward a bit before it engages the rifling, again resulting in hitting at a slight angle, and deforming the projectile. That effects accuracy. And it can effect it a lot.
The action itself effects accuracy as well. A less-rigid action is generally less accurate than a more-rigid action. And then there's the rifling. Projectiles are stabilized by RPM, not by how many inches they travel per revolution. That means the projectile velocity needs to be matched to the degree of rifling.
The cartridge itself- how consistent are the rounds loaded. What are the tolerances for powder weight? How consistent is the powder composition? Possible air pockets in the projectile, effecting overall weight and balance? Are the rounds consistent enough to result in the same velocity? What's the range of velocities?
There are more factors than that of course, but it's a start...
The barrel length is just one little variable.