Posse Comitatus Act and the US Military on the Border
On April 3, 2018, President Donald Trump proposed that U.S. military troops be deployed along the United States border with Mexico to help control illegal immigration and maintain civil order during construction of the secure, border-length fence recently funded by Congress. The proposal brought questions of its legality under the 1878 Posse Comitatus Act. However, in 2006 and again in 2010, Presidents George W. Bush and Barack Obama took similar actions.
In May 2006, President George W. Bush, in "Operation Jumpstart," ordered up to 6,000 National Guard troops to the states along the Mexican border to support the Border Patrol in controlling illegal immigration and related criminal activities on U.S. soil. On July 19, 2010, President Obama ordered an additional 1,200 Guard troops to the southern border. While this buildup was substantial and controversial, it did not require Obama to suspend the Posse Comitatus Act.
The Posse Comitatus Act limits the Guard troops to acting only in support of the U.S. Border Patrol, and state and local law enforcement officers
https://www.thoughtco.com/posse-comitatus-act-military-on-border-3321286