The states at ratification gave the federal government certain powers - powers that the state held exclusively prior to the ratification of the Constitution. Originally, the idea was that if the constitution didn't give the federal government the power, it didn't have it.
The federalists wanted a strong constitution and federal government, while the anti federalists worried about the centralizing tendencies of a central government. So in order to allay the concerns of the anti federalists, they added the Bill of rights, with the idea that no matter how powerful and centralizing the federal government became, there were some lines it could never cross in regards to the states or the people.
So the answer to your question is, the second amendment is to prevent the federal government from infringing on right of the people to own their individual weapons. This is necessary because if there was no individual right to own a gun (and thus participate in the militia), the sovereignty of the states would trend toward becoming subsumed by the federal government