I won't give a broad and complete answer, but your best case study for draconian laws likes this --in the ancient era-- is obviously Sparta. Otherwise, Septentrionalis gives a very good overview of the professionalism of military orders today.
Cowardice of course, was extraordinarily frown upon in Sparta (perhaps without equal), and retreat, as we all know, often goes hand and hand with cowardice. If you were deemed a coward in the Spartan Army, you could be put to death, or worse, shamed into suicide. But the question asks about uniformed retreat ordered by a superior, not the cowardly desertion of individual soldiers.
In this case, Sparta's "win or die / no retreat " mentality was a guideline, not an all-encompassing requirement. When ordered to retreat back to Sparta from Thermopylae,
Aristodemus became known as Aristodemus the Coward, but he was not put to death. When
Argis II (a Spartan king) withdrew a whole Spartan army from Argolis, he was publicly shamed, but neither he nor the other Spartans were put to death or imprisoned.
The real consequences of ordering a cowardly retreat then, in a society obsessed with Homer and glorious death on the battlefield, was not then legal punishment or execution to those who obeyed, but the sick and ugly expectation that you then, without any honor left, would kill yourself or die a thousand deaths.