I don't deal with immigration matters, but I do paperwork for imports of commercial goods into the USA. I've had plenty of interactions with CBP. I can tell you from experience that they operate with impunity. Customs brokerage is basically a legal profession and brokers usually know the law better than CBP officers do. But trying to cite the law to them will usually just cause them to double down on fucking up your day. And there's zero recourse. I've had officers hold my customer's shipments simply because they didn't know how to operate their own computer system to release them through, and making up stupid reasons on the spot to hold the shipment was the only way for them to avoid admitting they didn't know what they were doing. They make up their own rules or just do whatever they feel like in the moment and there's nothing you can do about it. That's officially how it is, even. Every international border point or air/sea port has a CBP official acting as Port Director, and they literally make up their own rules as to how the port operates. If something is permissible by federal regulations, they can contradict that and there's nothing you can do about it. And if you find out that your shipments are constantly getting held up because of the policies unique to a specific port, they will fine you for "port shopping" if you re-route your shipments through a different port that treats you better. If someone gets an attitude with them over their behavior or they simply don't like them, they'll destroy their small business by setting an automatic flag to have every one of their shipments held for inspection, and if they really don't like them, they'll even damage all their goods in the inspection process. I've heard story of one customer who was jerked around by CBP and said he was going to call his congress person. They laughed at him and held his shipment for 3 months.
On the other hand, I once saw a high stakes shipment that was "lost" by CBP for 3 days. In that much time, it got escalated all the way up to my company's CEO. Turned out our CEO is golfing buddies with the CEO of the airline the shipment flew in on. They made a couple phone calls, and the shipment was "found" and released about 15 minutes later.
Like most law enforcement, they desperately need a purge and establishment of third-party oversight. Welcome to the USA.