Don't confuse inherent accuracy of a given firearm with practical accuracy
Barrel length does not substantially change the inherent accuracy of an arm.
Longer barrels usually make for longer sight radius, the longer sight radius gives a better view of sighting errors (as so rightfully stated by 9mmepiphany). Normally, this makes 'sighting' easier, which enhances accuracy.
There are many issues which affect accuracy. The sighting mechanism (iron sights or optical device) much maintain the same relationship to the barrel for every shot. The quality of the barrel.
A rifle typically has an accuracy edge over a handgun of typically three to one (i.e. a rifle will shoot a group at 100 yards the same size as a comparable handgun will shoot at 33 yards; OR, at the same range, the rifle will shoot a group one-third the size of the handgun.) However, the difference is not all in the length of the barrel. The rifle with buttstock can normally be held to a tighter sight picture than a hand only (even both hands) handgun.
I remember a bullseye pistol maker (I wish I could remember his name now) in the 1970s and '80s who built match grade .45 and .22 pistols with the barrel counterbored (muzzle recessed) to the point where the actual barrel with lands was only about three inches long. The last two inches of the barrel the bullet was actually not in contact with the barrel. Of course the slide was unchanged and so the sight radius was still the same as a 'normal' pistol. The theory was last second twitches of trigger break and so forth didn't disturb the sight picture until the bullet was 'free' of the movements of the pistol. That seemed to work. It didn't work enough to justify the added expense.
Back to rifles: A rifle normally shoots better than a handgun, but the accuracy difference between an 18" barrel rifle and a 26" barrel rifle is not so much - all other factors being equal.
Anyone remember the .38 Special wadcutter chambered pistols used in Bullseye competition (Colt Gold Cup and S&W M52)? Those pistols were designed for maximum accuracy in the 'centerfire' category and were not restricted to five inch barrels. (As I recall, at the time, they were restricted to a 10" sight radius.) Both guns were highly valued precision pistols, but they both were designed with 5" barrels. Since they were designed as target guns, they could have easily been made with six or seven inch barrels. But they weren't.
In some disciplines - international union rules, I believe - some pistols had barrels of 'normal' length, but had extended front sights that made a longer sight radius.
My point is this: If - with all other factors being equal - a longer barrel always gave higher accuracy, then all the bullseye guns would have barrels as long as the rules allowed. That does not show up in the world of competition.