Each nation does things a little differently. Some have the divine right of kings, other theocracies. Others are nations of laws, others are oligarchies.
America is really an oligarchy at this point, but for most of its history was (theoretically) a nation of laws. Whatever the laws said, that is what the nation was constructed of. People did what they wanted to regardless of course. Consequently, much of what’s done in America is not so much “legal”, just “not caught yet”.
I don’t know how this applies in other nations though.