When you uncontract doesn't in "Why doesn't it work?" the not moves to "Why does it not work?"
This confuses me even more when I use a longer phrase instead of the pronoun it like below:
Why doesn't this simple code example work?
Why does the word order change when we use a contraction?