As long as it’s not discharging oil loaded in a US port in another US port it’s not violating the law, as far as I understand it.
The US flag foreign built container ships with MSP contracts will load in Long Beach, Oakland, and Dutch Harbor but not discharge any of that “US” cargo in any US ports. They’ll discharge all foreign cargo in US ports.
That’s how companies like Matson, Pasha, and Coastal survive. They service the JA trade from the mainland to Hawaii/Alaska where foreign ships can’t. Obviously Matson and Pasha have other endeavors but without their Hawaii trade they’d be competing with every other foreign company.