When you are flying a foreign flag docked in a port you are complex legal situation - in international law, you follow the laws of the flag country, in addition to being under local jurisdiction (most of the time). And if you’re flying a flag for a boat that’s not registered under that flag, which as this article explains is easily verifiable, who is going to buy the oil, and how? not to mention any possible international sanctions on the oil, customs, the crew getting paid and wanting to return home, wherever that may be, and you get situations that can last for a long time. For this case a boat to boat transfer may be the only real way.
Your comment hints at another problem, which is that allowing the cargo into a port possibly could be exploited as a loophole to break sanctions.
Yet another big problem is that cargo might be too low in value, or even undesirable. Like the cargo of Ammonium Nitrate that exploded in Beirut a few years ago (it had been taken off the docked ship which then sank in the port. The cargo was stored in the port, then stuck in legal and payment disputes, and the result was horrific).
Under international law piracy has the for “private ends” clause when defining piracy meaning nation states can’t really do piracy but instead commerce raiding which is a form of warfere.
these are usually very poor crew trying to escape desperate circumstances. they arent in a bargaining position and are easy prey to pirates depending on the part of the world they are in. Since they’re ghost ships, anyone could basically take what they pleased without anyone knowing, not to mention whatever country is willing to take an unregistered ship to offload oil in amounts that someone annoying could notice.
it’s a bad situation for everyone but the seller that convinced the ship it could turn it around.