This type of gate screening has been around for decades with varying levels of hassle and indecency.
In most cases, an "SSSS" on your boarding card indicates that you will be pulled aside at the gate (or at the checkpoint for departures from Canada and--usually--Frankfurt.)
In other instances, you are chosen at random or maybe not so much at random. They try to fill a particular quota of passengers.
There isn't a way around it. It's absurd that TSA Precheck does not apply to these screening scenarios, and there is no logical rationale to ignore it. But this is about security and theatre; logic is inconsequential.
On many airlines, the secondary screening consists only of swabbing bags or shoes. But other airports and airlines have much more intrusive questions, searching, swabbing, and frisking. Indeed, Iceland's Keflavik Airport has an entire separate room for all of the passengers who are flagged for swabbing and frisking.
The rules are set by the US government but there is wide variability in how these rules are enforced.