Professionals for a Massacre
aka: Red Blood & Yellow Gold
(1967)

Three bandits join the confederate army, but only to loot and pillage.  They are caught selling stolen weapons to Union soldiers, and are sentenced to be executed.  A confederate officer and his men steal a wagon of gold that was needed to buy weapons from Mexico.  The three bandits are freed, as General Sibley thinks they are his best chance of recovering the gold.  A lieutenant goes along to keep an eye on the bandits.

The gold has been stolen by a mexican gang.  The bandits recruit the confederate thiefs to attack the mexican gang together.  In the confusion of battle, the bandits kill off both the mexicans and the confederates.  The lieutenant pulls a gun on them.  He is really a union spy.  He calls in a Union cavalry patrol.  They are to kill the bandits and take the gold for the union.  Downey asks if they can say a final prayer.  With guns and dynamite hidden in his big Bible, the bandits kill the union patrol.

Just as they think they are free to leave with the gold, General Sibley shows up with the regiment.  He takes the gold, but fulfills his promise to pardon their death sentence and give them horses and equipment to leave with.  Sibley and the regiment take the wagonload of gold to trade for weapons. As the trade is being completed, the three bandits are in the seat of the wagon.  There is no explanation of how they got there.  They take off with the wagon full of gold, with both the mexican and confederate troops in pursuit of them.

Thanks Joseph C!