On the constitution gov website it discusses the origins which I referenced to:
The early American experience with militias and military authority would inform what would become the Second Amendment as well. In Founding-era America, citizen militias drawn from the local community existed to provide for the common defense, and standing armies of professional soldiers were viewed by some with suspicion.The Declaration of Independence listed as greivances against King George III that he had affected to render the Military independent of and superior to the Civil power and had kept among us, in times of peace, Standing Armies without the Consent of our legislatures. Following the Revolutionary War, several states codified constitutional arms-bearing rights in contexts that echoed these concerns—for instance, Article XIII of the Pennsylvania Declaration of Rights of 1776 read:
That the people have a right to bear arms for the defence of themselves and the state; and as standing armies in the time of peace are dangerous to liberty, they ought not to be kept up; And that the military should be kept under strict subordination to, and governed by, the civil power.
The theme of the excerpts is the necessity of an armed public in defense of the possible tyranny of the sovereign.