Muskets were inaccurate, even at close range. The states saw active militias as the only protection the central government would have against insurrection. This had just been proven, in Shays' Rebellion, an armed revolt against the government in Massachusetts. The Amendment wasn't written to enable such rebellions, but to put them down. As the Whiskey Rebellion of 1791 would be put down, by militias under President Washington.
That's the real Second Amendment. It's not this “everyone gets as many guns as they want” nonsense the so-called National Rifle Association spouts. No matter how many judges or politicians may agree with them, that is just not the historical fact. It's a fiction, a lie, and those who write it are liars.