Not illegal in this case, because the Customs and Border Patrol (CBP) is a department of the Department of Homeland Security, is not covered by the Posse Comitatus Act. Although the CBP is an armed service, it has a federal regulatory agency mission.
The Act only specifically applies to the United States Army and, as amended in 1956, the United States Air Force.