Vomitorius I don't know the border crossing rules, but I know there are quite lot countries, where in their airport after landing you must give phone to be extracted - by connecting unlocked - and if you refuse doing so, you can go where you did come from
Yeah, if you're not a citizen no country needs to allow you entry. They can pretty much set whatever standards they want, be it "hand over your phone" or "stand on one leg for ten minutes." Specifically, though, if you're a US citizen, they must grant you entry pretty much no matter what, but they also can take all of your stuff. So, if you're a citizen, your options generally are 1) comply and hand over the passcode; or 2) let them take your phone.
Aside from the expense of replacement, option 2 really isn't that bad, especially if your phone is in BFU state. Of course, option 2 also comes with potential ramifications like pissing off CPB, getting added to the no-fly list, losing perks like Global Entry and Precheck, getting secondary screening at every airport, etc.
And of course there's option 3, which is wipe the phone and then getting arrested.