When the result of not commenting the crime is magnitudes worse than the crime itself.
For instance, stealing an epipen to save a life - everything's grand. Stealing a paracetamol because you have a headache - yea, not ok.
Equally there are some specific laws that are just stupid, but I feel the above is a good cover all statement.