In the early days of criminal justice, punishment was often barbaric.
Public hangings and floggings were commonplace, and for lesser crimes, the infliction of public humiliation and pain on the criminal was considered necessary to deter others from committing similar crimes.
One such deterrent was to nail the convicted person’s ears to the hangman’s scaffold, where he or she would spend the day as a public spectacle.
They had been “nailed.”
We say that someone caught in a dishonest or criminal act “got nailed”.