Why was the 2nd Amendment added to the Constitution?
The Second Amendment was added to the constitution in order to create a well regulated militia.
When the amendment was ratified in 1791 the United States did not have a well organized army (unlike today [I should probably add at that time guns were incredibly inefficient]) to protect itself against invasion. The fastest and most seamless method of creating an "army" was to allow citizens to own firearms (all males at the time were expected to know how to use one even if they didn't own one). Also at that point in time anyone could be drafted to defend the nation at any time for literally anything (anyone who tries, or even suggests to do this today would not only have a mess to deal with but they'd probably be kissing their political career good-bye).
At that time the United States was not the unified nation that we have come to know. What we refer to today as the continental United States was a smorgasbord of many different nations that laid claim to numerous parcels of land. The north, in Canada, the French and British had land claims, while in the south in Florida, and the entirety of the west from Louisiana to California, as far north as Oregon and Washington State were claimed by the Spanish. These countries at the time were considered world powers, military powerhouses with an insatiable urge for expansionism, and if they decided to expand their territory (into the U.S.) they could have easily threatened the sovereignty of the United States. Arming citizens in a time when it could take several days for the military to respond to an attack, it was thought, would help thwart, or at least slow any pending attacks.
Update: I came across something on the internet today that I thought prudent to dispel. The article I read (from a prominent news source) falsely stated that the Second Amendment allowed for the unrestricted access to all firearms. The Second Amendment does not specify which weapons one can and cannot possess furthermore the Supreme Court has ruled that there are restrictions on what armaments a private citizen (that has not been convicted of a violent crime, including a misdemeanor [if you've been convicted of a violent crime you can never legally own a firearm) can own. Along with federal government regulations (argumentatively there aren't many of them) each state has the right to set any regulations that they see justified (in one of the states I reside in you can't own an automatic firearm nor can you concealed carry).
The debate on whether this amendment is still relevant is ongoing.