U.S. CBP actually has wide-ranging powers, not only at border crossings, but within 25 miles of an international border! The ACLU has put out a booklet on the subject:
https://www.acluaz.org/sites/default/files/field_documents/aclu_border_rights.pdf
Apparently people are stopped quite often in the vicinity of the Mexican border, even if they're not entering or leaving Mexico. See, for example: https://www.youtube.com/watch?v=fDCXzqgD99o
I (and every other car in line) was stopped on several occasions by U.S. CPB as I made my approach to the Detroit-Windsor Tunnel, and asked to show my passport. I actually read somewhere that exit controls were going to be made permanent, but that hasn't materialized so far.
I remember years ago when one complaint U.S. politicians commonly made about the U.S.S.R. was that you had to have papers and be inspected to leave the country.