How is it that taking a break from a problem sometimes allows you to figure out the answer? As a computer programmer, I have noticed an interesting phenomenon: If I am stuck on a particular problem in my work, often if I stop thinking about the problem and do something else, the answer will suddenly come to me.

Is there a name for this phenomenon? How does this work? Has any research been done on this? How is it that taking a break from a problem sometimes allows you to figure out the answer?

Edit: I remember now where I heard about this phenomenon: on the Charlie Rose Brain Series, Eric Kandel of Colombia University says (at 43:20 in)


  [The unconscious] can do many processes at the same time. You can either focus on one
  thing  or another, you can't focus on two or three things at the same time. Because
  consciousness is very limited in what it can do; unconsciousness is much broader. And
  although we know very little about the true nature of creativity, one emerging theme that
  comes out of this is that, if you're trying to solve a mathematical problem... if
  you're trying to solve any intellectual problem... you keep on focusing at it, you may
  get stuck. Taking a break, taking a shower, going for a walk, playing golf, you come
  back refreshed. And often doing the other activity, boom, the idea will come to you.


But then they change the subject! What is the concept he's talking about, and where can I read more about how it works?
It sounds like you're talking about a classic example of Incubation.


  Incubation is defined as a process of unconscious recombination of thought elements that were stimulated through conscious work at one point in time, resulting in novel ideas at some later point in time.


Here's a great article by John F. Kihlstrom: Intuition, Incubation, and Insight: Implicit Cognition in Problem Solving. Basically it is believed that Incubation or stopping conscious thought on a problem allows one to find more creative solutions to a problem:


  In these cases, Wallas argued, thinkers enter an incubation stage in which they no longer consciously think about the problem. Wallas (1926) actually distinguished this phenomenon between two forms of incubation: "the period of abstention may be spent either in conscious mental work on other problems, or in a relaxation from all conscious mental work" (p. 86). 
  
  Wallas believed that there might be certain economies of thought achieved by leaving certain problems unfinished while working on others, but he also believed that solutions achieved by this approach suffered in depth and richness. In many cases of difficult and complex creative thought, he believed, deeper and richer solutions could be achieved by a suspension of conscious thought altogether, permitting "the free working of the unconscious or partially conscious processes of the mind" (p. 87).1 In either case, Wallas noted that the incubation period was often followed by the illumination stage, the "flash" (p. 93) in which the answer appears in the consciousness of the thinker.


Kihlstrom's references contain many good experiments backing up the claims made.

A reason incubation may work is because it releases "fixation"; that case of being "stuck" which is a sort of mental rut which prevents one from thinking of new answers or methods of solving a problem. 

We become stuck on an idea that we believe should work but doesn't, which may hold us back from thinking of a different solution which actually does work, one we may have previously not considered or disregarded.

A great dissertation by Bo T. Christensen 
 covers both ideas of Fixation and Incubation in depth: Creative Cognition: Analogy and Incubation.