Let's take two questions: "What happened to you?" and "What happened with you?"
"What happened TO you" means what affected you, what event had impact on you.
A: You're really late. And you're limping. What happened to you?
B: I fell on my way here and sprained my ankle. But, I wouldn't let that stop me from meeting you. I came anyway, late or not.
"What happened WITH you" means what's going on with you, what's up with you.
A: You were really ugly at the meeting today. What happened with you?
B: Ugly? I guess I'm just tired of having all the work dropped on me. One of these days, I'm just going to quit.
Another meaning of "what happened/ is happening/ has happened with" is "what's the story?"
A: What happened with Marlene? Is she going to help you or not?
B: I don't know. She never returned my phone calls.
A: What's happening with the weather these days? It's hot one day and cold the next.
B: I heard it's because of El Nino.
Sometime both "happen to" and "happen with" are possible:
A: What happened to/with our teacher? She left early today, and in such a hurry.
B: I don't know. She must have gotten some urgent message.
A: What's happened to/ with you? Don't you love me any more?
B: I don't know. I'm confused.