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
The other way is not wrong.
Putting the not outside of the normal order causes more emphasis to be placed upon it, a rhetorical figure known as anastrophe. From NOAD: