It's legal by whatever state is saying it's legal. If they say it's illegal for Russia to export oil, it is legal for them to detain a ship they suspect of doing so.
That doesn't might it "right" or whatever, however you'd want to try and define that for something like this. It does make it not piracy though. Piracy isn't even necessarily "evil" either. It's a tool. States have sanctioned pirates against their opponent many times in the past. The difference is it isn't the state doing it then.