Civil War Discipline in the army was critical. This was no different during any other war and any other army.
Without proper discipline soldiers became nothing more than an angry mob that could not be controlled.
Because of this discipline in both armies was very strict and if any soldier committed any crime even a minor offense they had to be punished for it to maintain discipline within the unit and army as a whole.
The Provost Marshal in the Union army was responsible for maintaining and enforcing military rules. Most offenses were minor such as not taking proper care of equipment or not performing routine camp duty. These were often punished with longer hours on guard duty or doing tasks that nobody else wanted to do like chopping wood or digging latrines.
For more significant offenses such as cowardice in battle, stealing, or insubordination to superior officers there was more severe punishment. This generally included things such as wearing a board, which proclaimed your crime to everyone who could read, or carrying around a heavy log.
This was punishment by humiliation.
For the most severe crimes came the most severe punishment.
Crimes such as murder, spying, and desertion would often be met with being sent to a military prison or punishment of death, either by firing squad or hanging.
In the army it was probably in the best interest of the soldiers to follow the rules, otherwise…well you know.