This is known as the Euthyphro dilemma and it dates back to Plato.
If something is right because God commands it, then God could command that murder is okay and then it would be okay. God could command that rape and child torture are morally okay and so these things would be okay. To put it shortly, this makes morality arbitrary because something is right just because a person says so namely, God.
The other option is that God commands something because it is good. So God appeals to a standard outside himself. If God appeals to a standard outside himself, then we have no need for God as the foundation of morality.
However, theologians like Aquinas have noted that the dilemma is in fact a false one.
God’s nature is the foundation of right and the good, and God’s moral commands and duties follow from this nature. In this case, morality is neither arbitrary nor outside God.
Some have objected that this just pushes the dilemma back another step. “Is something good because it accords with God’s nature or is God’s nature good because He chose his nature?”.
I would answer that something is good because it accords with God’s nature. My opponent will now say that this is arbitrary because good is whatever God’s nature is. God’s nature could be different.
However, this is a gross misunderstanding of theism. God is a necessary being who is changeless, eternal, timeless, uncaused, self-existence, immaterial, and personal.
So, God’s nature can’t change at all. It is set in stone.