Part of the issue here is in understanding the situation at the time it was written as well as the purpose of was written for.
The US was just formed out of a war where the army had been formed out of locals and largely with personal weapons. If individuals did not have weapons, they could not have risen up against the government at the time to take their freedom.
The US was in a balancing act to try to maintain a cohesive federal government without stepping too much on individual states rights. The Articles of Confederation, the first pass at the US government, had shown itself too weak and so they came back with a stronger proposal. Individual states such as New York and Pennsylvania tied their identities much more strongly to their being New York and Pennsylvania than they were tied to being the USA. Hence the term State, which often means whole countries elsewhere in the world. As part of securing the Freedom of the State from the power of the federal government, the individual states were given the responsibility of managing their own militias. The USA was not meant to have a standing army, but was given power to rally the militias during wartime.
Putting militias into state hands rather than a standing federal army meant that states had the ability to protect themselves from abuse by the federal government. In exchange, sure to having dangerous frontiers and threat of war at any time, states were charged with maintaining and regulating militias so that they would be useful when needed.
The nature of militias is that they generally aren't full time soldiers. Further, being agricultural at the time, keeping weapons exclusively in central armories would inhibit the ability of militias to respond to emergencies. So it was common for people to keep weapons at their home so they would have something to use until they got to mustering points.
Preserving the right of people to keep their weapons meant that the federal government couldn't come in and disarm a populace before passing unpopular legislation. By being armed, the individual states could protect what they saw as their rights with force of need be.
Which brings us to the civil war. The south, feared the loss of their state rights to invade other states and abduct people they saw as property against the will of the state those people were in was being violated. (Yes, it was a states rights issue. Southern states wanted to violate northern states rights to say that people weren't property within their borders). So the south issued declarations they were leaving and mustered their militias for war.
After the civil war, the USA moved to the standing army model. Militias were severely undercut, though so still exist. National guard and national guard reserve are the big ones now I believe, which are usually named by the state that manages them. Someone can correct me if I am wrong on that.
The changes of time really make the old law seem like it fits oddly. We no longer rely on militias. People still have the right to keep arms in support of allowing militias to be formed and regulated. However, the technology of war has also changed so much that the original purpose of being able to quickly respond to war or fend off an overreaching federal government would require laughably permissive weapon ownership.
To uphold the spirit of the second amendment, The Ohio National Guard would be permitted to have nuclear weapons. Your neighbor would be allowed to keep a fully armed tank in their garage or build a jet fighter airstrip in their back yard. Live along the coast? Make sure you keep up maintenance on your nuclear submarine and it's payload.
The second amendment was stripped and severely limited over a hundred years ago. It is a zombie, a shell of its former self not even able to carry out its original intent.
I am not even against gun ownership. I just recognize that the second amendment is near useless and referring to it in order to try to keep an AR-15 at home is the same logic as your neighbor referring to it in order to keep an ICBM launch system. The line we are drawing with it for what weapons are acceptable to keep is completely arbitrary. And if the line is so arbitrary, then the amendment text is bad and needs to be rewritten and modernized.