Good question because that scripture screams that question every time it is read.
I don't believe that Adam and Eve successfully hid from God. How could they if God is omniscient?
And there is no creature hidden from His sight, but all
things are naked and open to the eyes of Him to whom we must give
Even before a word is on my tongue, behold, O Lord, you know it
So if God knows all, then the question becomes why did God ask the question, because it wasn't because he didn't know. So if the question wasn't for God's benefit, then it must have been for Adam's
If we process the whole scene, Adam and Eve had been in perfect relationship and fellowship with God until they disobeyed and sinned against God. Then all of the sudden Adam and Eve are trying to avoid God. When God asks the question, even in Adam's hearing of the question, he has to realize that something isn't right.
God has never had to ask this question before, because Adam had never hidden from God before. So for God to ask, let's Adam know even before he answers, that God knows something is wrong.
Even in the same scripture God continues to ask questions. God could've just came in and said "Adam and Eve you sinned and the serpent tempted you, here are your curses, see you later", but instead He questions them.
Then for Adam to answer he can begin to understand and process "where" he is in relationship to God versus where he was. Adam's position has changed, and he is not in the same place physically or spiritually.
God does this throughout scripture where He asks a question he already knows the answer to, but it is to the benefit of the hearer that he asked the question.
There are many scriptures where God asks questions, but indeed already knows the answer. Here are a few:
Genesis 4:6 NKJV
So the Lord said to Cain, “Why are you angry? And why
has your countenance fallen?
Genesis 4:9-10 NKJV
9 Then the Lord said to Cain, “Where is Abel your brother?” He said,
“I do not know. Am I my brother’s keeper?” 10 And He said, “What have
you done? The voice of your brother’s blood cries out to Me from the
1 Kings 19:9-10 NKJV
9 And there he went into a cave, and spent the
night in that place; and behold, the word of the Lord came to him, and
He said to him, “What are you doing here, Elijah?” 10 So he said, “I
have been very zealous for the Lord God of hosts; for the children of
Israel have forsaken Your covenant, torn down Your altars, and killed
Your prophets with the sword. I alone am left; and they seek to take
After Elijah's final answer God corrects him and gives him an assignment to go anoint Elisha
Hopefully this helps.