The legality principle, often encapsulated in the Latin phrase 'nullum crimen, nulla poena sine lege,' mandates that no one can be punished under a law unless it is established and published prior to the act committed. It ensures predictability and fairness in the legal system by prohibiting retroactive criminal legislation and arbitrary prosecution.