I find this true as well, especially when I'm working on things that require a bit of creativity.
I spend a lot of time making up mnemonics for memorizing Japanese characters - the only way I've found to really remember them is making up little stories for each. But, if I decide to just sit down and try to make stories for hours, it doesn't usually work. I can be stuck on a character for 10 minutes, then get up to go to the toilet, and figure out a story straight away when I wasn't even trying.
I've found the same thing with coding as well. Sometimes I'll be trying to solve that stupid bug, and spend an hour or so on it. Get up to have a drink, stop concentrating on it, and then it just all makes sense.
While daydreaming constantly obviously wouldn't be productive, I think its fairly certain that spacing your work out and giving your mind a chance to go off on a tangent is probably very good for getting things done that require problem solving and creativity.