I believe that the posse committatus law prevents the military from performing law enforcement jobs such as arresting and detaining. I don't think that building a wall on the border would come under any definition of that law that I have ever heard of.
https://www.law.cornell.edu/uscode/text/18/138518 U.S. Code § 1385 - Use of Army and Air Force as posse comitatus
"Whoever, except in cases and under circumstances expressly authorized by the Constitution or Act of Congress, willfully uses any part of the Army or the Air Force as a posse comitatus or otherwise to execute the laws shall be fined under this title or imprisoned not more than two years, or both."
(Added Aug. 10, 1956, ch. 1041, § 18(a), 70A Stat. 626; amended Pub. L. 86–70, § 17(d), June 25, 1959, 73 Stat. 144; Pub. L. 103–322, title XXXIII, § 330016(1)(L), Sept. 13, 1994, 108 Stat. 2147.)
The original provision was enacted as Section 15 of chapter 263, of the Acts of the 2nd session of the 45th Congress.
Sec. 15. From and after the passage of this act it shall not be lawful to employ any part of the Army of the United States, as a posse comitatus, or otherwise, for the purpose of executing the laws, except in such cases and under such circumstances as such employment of said force may be expressly authorized by the Constitution or by act of Congress; and no money appropriated by this act shall be used to pay any of the expenses incurred in the employment of any troops in violation of this section and any person willfully violating the provisions of this section shall be deemed guilty of a misdemeanor and on conviction thereof shall be punished by fine not exceeding ten thousand dollars or imprisonment not exceeding two years or by both such fine and imprisonment.
So while you are unquestionably correct, and I am not going to defend the wording of my prior comment, it is not just the statute which is at issue, but also the precedent and tradition of not using the military for NON-military functions. For example, we do not use the military to build highways in the U.S. simply as a means of holding down costs or to get things down quickly, even though the Corps of Engineers certainly has the expertise to do that, and we might not have any sort of combat operations at that time which would otherwise occupy the troops which might be used in road building.