Probably a simple yet complex question...

but, when you "realize" you're dreaming in the middle of a dream plot, like noticing that nothing here makes sense, what actually goes on in your brain?

From what I know, the logic center is turned on. But surely something causes this to turn on right? It seems weird that all of a sudden we can realize we're dreaming when the nature of most dreams is to make up a reason why all of this makes sense, to prevent the logic center from turning on.

I mean, isn't questioning reality in your dreams itself already using logic?
"this doesn't make sense, therefore i should reality check." <--- logic.

or is it just a habit that carries over to your dreams? but even if that's the case, i'm still stumped on how that would trigger the logic area of your brain to turn on, because sometimes dreaming about lucidity won't make you lucid either.