There’s always a deeper reason to why God asks questions He clearly knows the answers. Like Jesus asking the woman “who touched me?” Or asking the woman at the well to get her husband, or Peter, “Do you love me?” the first question out of the gate out of the garden was “Where are you?” Not to shame them (they already did that to themselves) but to locate that shame as a flight from intimacy from Him, exposure that they were no longer loving Him.
Secondly, the next question revealed that they were no longer listening to Him: “Who told you…?” This was to locate their faith as distanced from Him.
Then, and only then, does behavior come into the picture with “What have you done?” Disobedience is the fruit of that process in an attempt to feel better. Works of the flesh are just that: OF the flesh.
The Gospel answers all three those questions, in that order. God first reveals His Worth, through His Word, by His Way. All Personified in Jesus. Faith and repentance lets us reverse our sin-filled, shame-soaked direction.