I'm no expert on 19th century military justice, but today's code punishes moral and disciplinary failings, not tactical incompetence. Assuming the code then was reasonably close to what it is today, court martialing a general for losing a battle just doesn't make sense. (If there's some disciplinary failing that can be shown to be the cause of the loss, that's a different story, but such things aren't really modeled in AACW.) The proper remedy for incompetence is removal and replacement.
In order to model courts martial, you'd have to assign the generals personal vices like drunkenness and whatnot, then come up with a system to determine how far those vices affected a battle, how likely the general's superiors were to prosecute him for them, etc.
I think doktor57's Joint Committee on the Conduct of the War idea is more like what you're looking for, except that it didn't execute people and often did more harm than good by saddling the Union with incompetent but politically correct (i.e. hardcore abolitionist) generals.
That said, string the bastards up!!!
