I cannot speak to the laws of other jurisdictions, however, “necessity” or “choice of evils” was a common law defense and has been adapted by many jurisdictions, including Kentucky. A link to the Kentucky statute is below. You can google those terms in your own state’s statutes under justification and/or defenses.
It generally means that it is a defense to the commission of a crime that the offense committed is justifiable when the defendant believes that it is necessary to avoid a public or private injury greater than the offense prevented by the offense charged.
For instance, busting the window of a car out to get a child out who was left in a car on a hot day would be justified.
https://apps.legislature.ky.gov/law/statutes/statute.aspx?id=19667