Walter Mitty's daydreams are a form of escape from the boredom of everyday life. His real life is characterized by boredom, routine, lack of satisfaction, and a nagging wife. His dreams, on the other hand, involve being a bomber pilot, facing a firing squad, and being on the witness stand in the courtroom revealing that he is a talented marksman, and having an attractive young woman fall into his arms.
Real life is juxtaposed against a world of excitement and fantasy, and since Walter is unable to create any excitement in his real life, he escapes into these fantasy worlds at every given opportunity.
His wife, who seems to have no understanding of her husband's lack of satisfaction with his life, treats his fantasies with disdain, informing him at one point that she will need to take his temperature when they get home. I would argue that his unhappiness in his marriage makes his boredom with his life worse, which in turn leads to more of the daydreams which his wife so derides.
In a nutshell, Walter's daydreams are caused by the same factor which makes some people escape into books, others gamble, and yet others have extramarital affairs. He is looking for...
an escape from the mundane nature of his everyday life.