Is this a law that God is legally required to uphold? Eh... I suppose you could think of it as such, but then it gives off the wrong impression about how God might be subject to some mystical legal system that He doesn't control.
This is an important point, btw, regarding God and His morality and laws.
Let me give an example:
Everyone knows how the US government has classified information: Confident, Secret, Top Secret.
The president of the United States is legally the Original Classification Authority of all classified information. He is the top person who says what's classified and what's not, and other "delegated" classification authorities (such as the Director of the CIA) can only classify information within the president's guidelines.
What the president says is classified, is classified. What the president says is not classified is not classified.
Moreover, it's impossible for the president to "leak" classified information, because whatever previously classified information the president releases to the public
instantly becomes unclassified the moment he speaks it publicly.
This happened several times during my time in the military. The president would say something in a news conference that revealed classified information, and the very next day we were "correcting" all our documents to reflect the fact that that bit of information was no longer classified.
So, God is the "original moral authority." God is not subject to some higher moral authority. As the original moral authority, God cannot do anything immoral because
whatever God does is moral because it's God who does it.