Uh.... realistically, in the real world, where people aren't being obtuse, police exceed their legal authority periodically.
Police have a wide range of latitude to determine that a situation is an emergency and can do a number of things to prevent the emergency from getting worse. Things have changed significantly now that many police are required to wear recording devices- it's now clear that some police abuse their authority.
It’s even worse than that. This stuff can show up in background checks. Just being arrested, regardless of guilt, shows up and possibly prevent you from getting a job.
In many US jurisdictions, police will show up if they get called with a complaint. They'll harrass the person the complaint was about, and if they don't like how the person responds, they'll escalate the situation. The number of people charged for nothing except "resisting arrest" (regardless that the arrest was unreasonable) is astounding.
And there's no "right" way to act in those situations. Charles Kinsey got shot, lying on the ground with his empty hands on the air, because the police were afraid when they responded to a complaint. The shooter kept his job, retired, and got 100 hours of community service and had to write a letter of apology.
Out of curiosity, do you not live in the US? This line of questioning is indicative of a lack of familiarity with US policing.
That being said, there are lots of crimes which could start with loitering outside a school, even if the locality doesn't have a law specifically against loitering in front of schools (which many do), loitering with intent to commit a crime is against the law, and the police only need "probable cause" to arrest you. "Looked suspicious and refused to move on when asked" could very well be enough to establish probable cause.
They walk up to you and ask a bunch of aggressive and threatening questions. You will obviously react in some way, either by getting nervous or upset at their questions. It doesn't matter which reaction you have, they will then say that your reaction made you suspicious, so they detained you.
The police can arrest you and take you to jail for a day. Then they can release you without pressing charges. That's perfectly legal. There's a time limit when they have to press charges or release you. They just release you before that time limit is reached. That's how the police prevent you from doing anything they don't want you doing whether what you're doing is against the law or not.
It's the standard and formulaic contraction for shall not, as well as part of the title of one of my favorite albums by contemporary chap-hop artist, Mr. B. and it's worth a listen at https://www.youtube.com/watch?v=CCAVTtDxvC8