The legal framework is that searches are permissible incident to a border crossing and some distance from the border after a recent border crossing.
CBP won't get away with using that rule to search someone that has not recently crossed the border.
When they setup checkpoints, they can't do arbitrary searches (they can just check vehicles for aliens). So they have less leeway in those situations than when they are doing a border search.