Walter Mitty's daydreams are inspired by what is happening in his real life. For instance, when he is driving his wife to an appointment, he daydreams he is commanding a crew flying through a dangerous storm. At the end of the story, Mitty's wife suspects something is wrong with him and says she is going to take his temperature when they get home. The implication is that she is going to start to question him about his behavior and may try to get him to reveal his daydreams. This would signal the end of his imaginary life because his wife would want him to give up his fantasies. So, as Walter waits on the street for his wife to buy one more thing, he daydreams he is in front of a firing squad. He is saying, in effect, I'll never give up my daydreams, even if they kill me. In fact his last words to himself are courageously-—"Walter Mitty the Undefeated, inscrutable to the last."
My teacher told us that at the end, he gives up in listening to what everyone has to say and feels his life has no meaning, so he dies/kills himself because he believes (sorry for spelling) that his life has no value compared to his daydreams. This also emplies that he is meek, and that the meek who are not capable of standing for themselves will also feel the need to kill themselves/suicidal thoughts/die.