It has sometimes been asked whether God commands certain things because they are right, or whether certain things are right because God commands them... I emphatically embrace the first alternative. The second might lead to the abominable conclusion... that charity is good only because God arbitrarily commanded it - that He might equally well have commanded us to hate Him and one another and that hatred would then have been right.
I believe, on the contrary, that “they err who think that of the will of God to do this or that there is no reason besides His will.” God’s will is determined by His wisdom which always perceives, and His goodness which always embraces, the intrinsically good.
But when we have said that God commands things only because they are good, we must add that one of the things intrinsically good is that rational creatures should freely surrender themselves to their Creator in obedience. The content of our obedience - the thing we are commanded to do - will always be something intrinsically good, something we ought to do even if (by an impossible supposition) God had not commanded it. But in addition to the content, the mere obeying is also intrinsically good, for, in obeying, a rational creature consciously enacts its creaturely role, reverses the act by which we fell, treads Adam’s dance backward, and returns.
From The Problem of Pain