Beans is right. Up to and including WWI it was a capital offence. We have a better understanding these days.
George Carlin did a very clever presentation on this. It runs for about 9 minutes but is well worth listening to. It's all about how shell shock evolved into battle fatigue, then into operational exhaustion, then into PTSD.
It is normal to be frightened in battle. If cowardice were punished, there would be no armies. ACTING from cowardice such as desertion in the face of the enemy is usually a capital offense.
In WW2, the American army had one such soldier who was executed.
My WW2 U.S. Army father said he never actually shot any Nazi soldiers. He shot over their heads. However, he also "assisted a sniper to locate targets." He was awarded a bronze star for doing "something".