I think that this is one of those cases where you can either spout "air law" (which in this case has nothing to do with it) or consider the practicalities.
There are many, many such cases.
Frankly, legal concerns should be the
last thing on a pilot's mind in an emergency. Like the old saying goes, "I'd rather be judged by 12, than carried out by six". In any event, the pilot in command has considerable discretion in such situations, and the risk of prosecution (let alone conviction) is very low.