In the short story "The Secret Life of Walter Mitty," it's clear that Mitty's demanding wife and overall disappointing life are the causes of his daydreams.
Each daydream is caused by something his wife did or said.
For example, the first daydream of him piloting a submarine is interrupted by his wife who tells him to slow down and then, in a nagging voice, says, "What are you driving so fast for?" While this event happens after his daydream, it's still his wife who precipitates it.
Then she suggests that he get medical attention for his daydreams.
Each daydream deals with his attempt to escape his wife's control, but at the end, as he has probably done his whole marriage, he succumbs to both his wife and his imaginary firing squad.
In The Secret Life of Walter Mitty, the daydreams are caused by Walter Mitty's boredom. Walter Mitty leads a drab boring life and even he is bored by his own existence. His daydreams are a way to escape this boredom and provide him with some sort of entertainment. In his daydreams he depicts himself as the man he wishes he could be. A fearless leader in some sort of action packed adventure. However, the last daydream he has is symbolic of how in the end his daydream is just a dream and he must return to his boring reality.