Quite a few Vietnam era (and earlier) trial judges offered men the choice of enlisting or going to jail.
i.e It wasn't a punishment, but a way of avoiding punishment. Civilian judges liked it because it got the youngster out of the jurisdiction, and got him into the armed forces with a chance of getting some discipline.
This is no longer allowed by the armed forces recruitment regulations. A relatively recent example which illustrates the enforcement.
I think the lyrics are "Got in a little home town jam", but that doesn't change the point.