International law. SOLAS and UNCLOS. SOLAS is The International Convention for the safety of Life at Sea, 1974, UNCLOS is the UN Convention on the Law of the Sea. It's UNCLOS that features in the ongoing IRAN war, re free passage of ships.
You can download SOLAS here.
SOLAS : (un.org)
And UNCLOS is here.
UNCLOS+ANNEXES+RES.+AGREEMENT
I am not familiar with SOLAS, but I know a bit about UNCLOS, and the bit of that that applies is article 98. SOLAS is a lot more involved, but art 98 of UNCLOS gives the gist.
"Article 98
Duty to render assistance
1. Every State shall require the master of a ship flying its flag, in so far as he can do so without serious danger to the ship, the crew or the passengers:
(a) to render assistance to any person found at sea in danger of being lost;
(b) to proceed with all possible speed to the rescue of persons in distress, if informed of their need of assistance, in so far as such action may reasonably be expected of him;
(c) after a collision, to render assistance to the other ship, its crew and its passengers and, where possible, to inform the other ship of the name of his own ship, its port of registry and the nearest port at which it will call.
2. Every coastal State shall promote the establishment, operation and maintenance of an adequate and effective search and rescue service regarding safety on and over the sea and, where circumstances so require, by way of mutual regional arrangements cooperate with neighbouring States for this purpose"
While most States, including the UK, have their own laws that mirror SOLAS and UNCLOS, SOLAS especially can be, and is, prosecuted in international courts.
It is international law that assistance be given, if safe to do so. And it is worth noting that these laws are outside of the ECHR. These are world laws. UN convention laws.
Here is an example of SOLAS laws being used, although here it is being prosecuted under Greek versions of Intl law. And if Greece had not acted, these officers would most likely end up in an international court. Or alternatively, if the Greek Government had ordered the Coastguard to do this, then it would be them in court.
Greek Coastguard Chief Faces Prosecution Over Deadly 2023 Migrant Shipwreck (greekcitytimes.com)
I am not a lawyer. But that is my understanding, and that is roughly how it works.