Don't worry they do it to citizens too. On one occasion CBP told me they would not let me enter the country. On another they imprisoned me for ~12 hours, on another they asked me if I work in the US and tried to demand ever more intrusive questions about it.
... I am us citizen presenting with us passport, look and talk extremely white with no foreign accent.
The situation resolved in my passport being flagged, feds executing a fruitless search warrant (thankfully the doctors would not go through with the full cavity search but i am in debt for the warrant), and lawyers telling me I'm SOL. Everytime I go to the border I make sure my affairs are in order to be disappeared. It's good advice for anyone entering the US.
Edit: just remembered the time they were enraged they had to let me in so threatened to revoke my passport.
I assume it has to do with a federal law that grants immigration agents broad searches and inspections and technically the Fourth Amendment does not fully apply as long as they are within 100 miles of the border or in the functional equivalent of a border (like an airport). The ACLU has a summary page about this.[1]
Lady named Cervantes had doctors warrantlessly finger raping her and lost due to jurisdiction fuck fuck games ( i also talked to her lawyer). Happen all the time, CBP lost once iirc in new mexico and letters were sent and thenn promptly ignored. CBP bragged to me about it. They also bragged about flagging trans people claiming their surgical dong was drugs and sending them for exam to fuck with them.
It's not just about security, they admitted they fuck with innocent people just for enjoyment. They cannot be stopped as the courts don't really see them as beholden to the Constitution, it's a huge legal hole and the officers have a crystal clear understanding of this.
This is also why when they needed an unbeholden army to send to Portland to pick up protesters in unmarked vans, they used CBP.
... on the US allied side. The government has known this for 10+ years, if it was illegal I'd have already went to jail. Look up Ashley Cervantes case if you don't believe it can't happen to anybody.
... I am us citizen presenting with us passport, look and talk extremely white with no foreign accent.