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).
let the crew paint a new flag for the country they want to dock at.