I was wondering which one is grammatically correct between "Why didn't (or did not) somebody do something?" and "Why did somebody not do something?"
Either works from a grammatical perspective, but usually a native speaker would say
Why didn't somebody do something?
The other way is not wrong.
Why did somebody not do something?
Putting the not outside of the normal order causes more emphasis to be placed upon it, a rhetorical figure known as anastrophe. From NOAD:
anastrophe |əˈnastrəfē| noun Rhetoric
the inversion of the usual order of words or clauses.