Several people commented along the lines of "take a break and do something else and it will come to you".

This has happened to me enough times that I really started to think about how/why it worked.

My theory is that it puts your mind into a different problem solving mode, similar to problem solving in the dream-like state, which I've also experienced. This seems to allow greater creativity, new approaches, and synthesis.

I've learned to love my dry erase board at work. When the mental block is on full it sometimes helps to step back and diagram the problem showcasing both flow and\or expectation of how the code is intended to work. More often than not, if there is a problem in logic, it becomes apparent from the flow and if it is a choice of code function, the expectation becomes apparent. Dry erase makes it easy to edit and if all else fails, I guess sniffing the marker comes to mind.