Check out the book The Psychology of Computer Programming by Gerald WeinbergThe Psychology of Computer Programming by Gerald Weinberg. Originally published in 1971 it was recenlyrecently produced in a Silver Anniversary version. I own an original copy and read it again about every five years. Weinberg and Glenford Myers both wrote amazing texts which will be useful forever.
In Weinberg, the situation you are describing is specifically addressed, and in his explanation says it is the result of knocking down preset pathways cognitively, then when you have to reestablish them you have cleared some cognitive assumptions placed there in the initial thinking of the problem. He also identifies the simple event where you begin to expalinexplain the problem to another only to suddenly discover the solution whereas it eluded you for hours before. This, again, results from employing different neuronal circuitry when we speak out loud versus when we are doing slow thinking (a la Daniel Kahneman, Thinking Fast and Slow). Weinberg's work is FULLfull of fun explanations and examples of how weird software engineering psychology can be. :) Cloud9Concepts.com