Why did God ask? He already knew the answer. He knows everything. So why did He ask?
Perhaps it was because He, being a merciful God wanted to forgive Adam and Eve. But, He could not do so UNTIL Adam and Eve saw the NEED for being forgiven. In order to see the need, they would have to take responsibility for their sin.
"Yes, Father. I ate the apple. I am so sorry. I shouldn't have eaten it, even though Eve ate it, too. It's not Eve's fault that I ate the apple. I could have said no, and I know You would have given me another Eve. But, I was just as curious, and I am at fault. Now I am ashamed. Please forgive me!
Instead, Adam said, "Yes, I ate the apple. It's all Eve's fault! She's the one who gave it to me!"
That was not the excuse God was looking for. The perfect excuse would have been, "I messed up. I was wrong. I promise I'll never do it again." (I don't think Adam even thought about not doing it again...)
And God did the only thing He could do. He made them live with their decision before finalizing His judgment.
This, of course, is speculation.
“He that covereth his sins shall not prosper: but whoso confesseth and forsaketh them shall have mercy.”