Mike, when you say legally, are you asking about who is empowered by law? If so, I would say only the building official and a judge have that power. When a zoning violation, or even a public nuisance is being pursued, only an injunction can legally stop someone from doing something. I took people to court many times to seek compliance and unless the judge ordered them to stop, they would pay the fine and I would have to refile charges.
The only exception I am away of the power of the bulding official. Even then, that is limited. There has to be a serious hazard and I would go so far as to say an imminent danger, before I sign a Stop Work Order. A possible exception would be if a partial plan approval were issued, say a foundation start, and framing is starting and the truss drawings had not been submitted, then I may stop work. But even the building may be okay so I would probably talk to the design professional to determine where the submittal is.
Perhaps a better example would be seeing concrete strength reports on a concrete frame building with consistently low 28 and 56 day breaks. I again would discuss the issues with the design professional before issuing a stop work order, even then, if they have a logical corecction plan and are doing it, I would give them the benefit of the doubt.
On the otherhand, a contractor who argues every inspection, a design professional who was not retained for construction administration, and a property owner taking a hand off approach, I would probably given them a 30 day notice before shutting the job.
The reason for all this hesitancy is the reality that the parties will cry to the elected officials, or cry to the media, and even if you are dead right, you will spent a lot of time explaining a very technical subject ot lay people with an agenda to make a government official look bad.
From a contractual basis, I recall AIA contracts typically had strong language that the owner could stop work but it has been years since I ran a large job with a decent contract.
Don Phillips