They had another 788 there that would have performed a scheduled flight JFK WAW. They cancelled that flight and transferred the pax on the Cancun flight airside to the other 788.
The pax on the JFK flight where rebooked. Being already in the US they had visas.
Operationally clever - safety wise very questionable.