It's anticipatory obedience, "a situation where one attempts to predict expectations others (particularly superiors) have, without explicit communication, and to fulfill (or exceed) those expectations.", see https://en.m.wiktionary.org/wiki/anticipatory_obedience
Most likely, this wasn’t official policy — just a low-paid border agent on a personal power trip.
Give a man a uniform, and watch him turn tyrant. The Stanford Prison Experiment says hello.
The real problem is that the US system allows individuals with minimal training and virtually no oversight to wield unchecked power over travelers' lives.
This is really just the essence of bureaucracy - which is the problem with these rules that sounds fine if you don't think about the implementation of them.
Trump himself probably wouldn't care (which is why he thinks these rules are fine - he knows what should be a jailable offense) but of course the bureaucracy needs to make rules that any of the thousands of border guards can follow. The outcome is a bullwhip effect and you get this (or worse).