Both forms are grammatically correct.
1- “What happened?”
This is a subject question because ‘what’ (the question word) is the subject of the verb happened.
2-“What did happen?”
This is an object question
for example:
I helped him.
Q1: Who helped him? (I) I did.
Q2: Who did you help? (him) I helped him.