From the NET bible translation notes:
John 2:4 tn Grk “Woman, what to me and to you?” (an idiom). The phrase
τί ἐμοὶ καὶ σοί, γύναι (ti emoi kai soi, gunai) is Semitic in origin.
The equivalent Hebrew expression in the Old Testament had two basic
meanings: (1) When one person was unjustly bothering another, the
injured party could say “What to me and to you?” meaning, “What have I
done to you that you should do this to me?” (Judg 11:12, 2 Chr 35:21,
1 Kgs 17:18). (2) When someone was asked to get involved in a matter
he felt was no business of his, he could say to the one asking him,
“What to me and to you?” meaning, “That is your business, how am I
involved?” (2 Kgs 3:13, Hos 14:8). Option (1) implies hostility, while
option (2) implies merely disengagement. Mere disengagement is almost
certainly to be understood here as better fitting the context
(although some of the Greek Fathers took the remark as a rebuke to
Mary, such a rebuke is unlikely).
According to the above reference, the phrase is a Hebrew expression that basically has two meanings, one that implies hostility and the other, disengagement. The way the phrase is used by the demons in Mark (5:7) and by Jesus in John (2:4) reflect this difference. Mark (5:7) implies hostility, whereas John (2:4) conveys disengagement.
While the reason the phrase is employed by the demons seems clear, why Jesus uses it is much less so. However, his words draw a connection between the wedding at Cana to a seemingly unrelated event, an hour that “has not yet come.” They effectively juxtapose the first act of his public ministry against the last hour of his life.
From this perspective, Jesus’ response to Mary leads me to consider another and broader context for Mary’s observation that “they have no wine.” At Cana, Jesus’ words imply that the purpose of his coming is not to provide for the physical thirst of mankind. At the same time, they point to an hour when he will pour out his blood to provide for the spiritual thirst of all the world.