They are stopping at other ports but legally don't have to in this case. The ship could go from NYC to San Juan and back and it is legal. This comes up often when people ask why a ship can leave Miami and it's first stop be Key West. Those cruises always continue on to some foreign port prior to returning to Miami, and are thus legal.
I have first hand experience with a cruise that didn't stop at any foreign port. We did a repositioning cruise once that started in San Juan, stopped the next day at St. Thomas, and then did two sea days, ending in Miami. All U.S. territory.
The Puerto Rico exception is only allowed as long as no U.S. flagged ship starts doing service to Puerto Rico from the U.S. mainland.