Even though the law says they have to let you in eventually, it doesn't say they can't harass you just in case you fall for it. They can also offer you a reward like less harassment if you just comply.
"They have to let you in" means that they don't let you in and you might be able to get a payout in court.
Nobody at the border has the job of "Force the border agent to let in anyone who is an actual American because they have that right", and nobody holds a gun to the border agent's head if he does not let you in.