...target rifles with heavy 26 inch barrels get much better accuracy than the same caliber rifle with a shorter light weight barrel.
You're changing two variables at once. Heavy barrels tend to be more accurate than light weight barrels and target rifles tend to be more accurate than rifles with light weight barrels. So yes, a long, heavy barrel on a target rifle will probably shoot better than a short light barrel on a regular rifle.
If you compare two barrels that are identical in every respect except length, the shorter one will tend to be more accurate.
Accuracy is the result of many things. All things being equal other than length; a longer barrel should make the shooter more accurate.
Barring the use of iron sights, a longer barrel will not make a gun more accurate. And it's not so much barrel length that stabilizes a gun as barrel weight. In fact, some target shooters who use iron sights use a short barrel with a sight extension, bloop tube and/or barrel weights so they can get the benefits of a long sight radius (and improved handling characteristics) without the disadvantages of the long barrel.
Its all in the angles. If you allow that the breech is fixed then the pivot of the barrel one way or the other means the muzzle must move more in order to move the direction of the projectile's travel. A shorter barrel points faster.
None of this has anything to do with the accuracy of the barrel, you're talking about handling qualities of the gun. Those can contribute to the overall accuracy of the
combination of shooter and gun but that's really not the focus of the original question.
A longer barrel might provide more or less velocity depending on the caliber and the length of the barrel (.22LR in a long barrel is actually probably losing velocity if you get up past 20") but regardless, trajectory isn't really an accuracy issue as much as it is a range estimation issue and, at any rate, unless we're talking pretty significant changes in barrel length (and therefore velocity/trajectory) it's going to be hard to see significant differences in trajectory.
Wind resistance is also dependent on velocity so if you're factoring in the wind a longer barrel might help a little, but again, that's an external factor, not really anything to do with the inherent accuracy of the barrel.
The comment about stabilization is correct--if you have a marginally stabilized bullet in a caliber that will benefit from a longer barrel (in terms of velocity) then increasing the barrel length could help accuracy by increasing the spin rate of the bullet--conversely reducing the barrel length in this very unusual case could destabilize the bullet further, hurting accuracy.
I should point out again that we're really splitting hairs here. It matters very little in practice for a variety of reasons. But if one is just interested in the theory of accuracy, short barrels win.