Definition - What does Necessity mean?
Necessity is a legal defense that is taken when a person breaks the law to prevent a greater breach of law from occurring. There are two main types of necessity: private and public necessity.
In private necessity, a person can trespass on another person's property to protect an interest of their own without being charged criminally for the trespass. Although the person would still be liable for any monetary damage made as a result, they would not be charged punitively or criminally.
In public necessity, a person can trespass for the benefit of another person who might be harmed by not doing so. In public necessity, the person whose interests were being protected is the one who would have to pay for monetary damage.
Justipedia explains Necessity
A person that is able to claim necessity can also stay at the property without being legally ejected if the reason why the person initially went on the property is still ongoing. An example would be to help put out a fire.
This kind of defense has also been used when farmers shoot dogs that trespass onto their sheep farms (to prevent the dog from killing or scaring the sheep).