Since God created everything, he also knows how to bring us the most pleasure and joy. Believe it or not, God wants to maximize our pleasure, therefore he tells us to be obedient.