WHile the Mormons claim they became Militaristic in response to non-Mormon opposition to them, the record is not as clear. The Mormon were a tight group of people who started to train together as a Military unit. This history is Complicated by the Anti-Mason Movement of the 1830s. In 1827 an Ex-Mason had reviled the secret rituals of the Masons, and his local lodged members Kidnapped him and later killed him for it. The Murderers were acquitted by a Mason dominated Judge and Jury. This started a Huge Anti Secret Societies movement in the US leading to the raise of the Anti-Mason Party.
Now the Mormons adopted many rituals that look like they were derived from Masonic rituals, thus the Anti-Mason movement of the 1830s might have been viewed as Anti-Mormon by the Mormons (In fact the Anti-Mason party was more anti-Secret Society than Anti-Mason, even nominating a former mason as their Presidential Candidate in 1832). Thus the Mormons may have just been reacting to the growing Anti Secret Society movement when they decided to arm themselves. This was further complicated by the tendency of Mormons NOT to want to deal with Non-Mormons, further putting them away from the rest of Society.
More on the Anti-Mason Party:
http://en.wikipedia.org/wiki/Anti-Masonic_Partyhttp://www.ohiohistorycentral.org/entry.php?rec=844 Anyway, no matter what cause the Militarization of the Mormons, it happened and they even fortified the town they were living in, restricting who can come in a trade and who could not. When the Mormons were outlawed by the Missouri Governor in the 1830s it was more to do with the fact they were the strongest single Military force in Missouri AND they had no dealings with the rest of society than any real hostility to the Mormon Religion per se.
Anyway, this militaristic attitude continued for many years and in many ways maintained to this day and is reflected in this legend. A good Mormon has to keep a years worth of food just in case it might be needed during a crisis. This by itself in NOT bad Idea, people should be prepared in case of a disaster, but with the Mormon it is tied in with their belief they are the new promise people who God intend to take over this Country at a time of criss. In many ways the Mormons are waiting for that time and try to keep their members ready to act at that time. By making sure they members have a years worth of Food means that during a Crisis the Mormons will be able to move while everyone else is looking for they next meal.
During the Mexican War, the Mormon joined the US Army as the Mormon Battalion and fought throughout the Southwest. The Bonus money for enlisting was used by Joseph Smith and most of the rest of the mormons to move to Utah. As to the troops they had a very good reputation during the Mexican war, showing a level of professionalism equaling the units that after the Civil War would become the National Guard and even the Regular Army (The US Militia was NOT used in the Mexican war, only "Volunteer" Units were used to supplement the Regular US Army). This level of professionalism was maintain throughout the mid 1800s (and might even be maintained today as far as I know, through I have NOT read anything about Mormon Militarism since 1859 when it was dropped as part of the deal to get the US Army out of Utah).
As I said, I have NOT read anything more current than 1859 as to the Mormons maintaining troops independent of the National Guard, but aspects of their former militarism can still be seen in they storing of Food and these legends.
Just some comment on Early LDS history and these legends.