"The next day" is an expression that can be used either as a noun or an adverb. There are many such expressions. Other examples are: "today", "yesterday", "tomorrow", "the day before", "the year before (or after)", "the day after", "the previous day", "next year", "last year", "mondays,..."
In your first sentence, "the next day" behaves as an adverb that modifies "happened".
In your second sentence, "the next day" is a noun which is the object of the preposition "on".
Here are some examples of nouns acting as the object of a preposition. In each case, if the preposition is removed, the noun changes into an adverb:
"What happened on mondays?"
"What happened before (after, until) yesterday"
"What happened during last year?"