Before 2A was drafted, several colonists used firearms to defend themselves because they usually lived far from each other. At the same time, communities also established militias for various purposes, including slave patrols. The right to defend oneself was considered natural, with the right to bear arms connected to it and part of English common law.
After the Revolutionary War, Washington wrote about the poor quality of some militias.
While 2A was drafted and revised several times, framers debates on the need to avoid a large standing army, state rights to have their own armed groups, the desire to avoid tyranny, and threats including European invaders, whites who could rebel, slave riots, and Native Americans. They negotiated and ratified an amendment that argued that to ensure the availability of regulated militias, the right to bear arms would not be infringed. The idea sounds too obvious because several colonists were already armed and it was considered a natural right, part of the need for self-defense. This explains why 2A doesn't grant the right to bear arms but protects it: the right is natural and exists even without 2A, the Constitution, or even a nation. Still, the added something obvious because they wanted to show citizens that their right to defend themselves would not be infringed.
So, what's the connection between that and regulated militias? The framers didn't argue that the right to bear arms is granted by the government or that the right only exists if there are regulated militias. Rather, the right to defend oneself, which is natural, was used to justify the need to defend the country. Since they didn't want a large standing army, they resorted to militias, and since they didn't want ill-trained militias, they made sure that there were regulated ones.
What does "regulated" mean? It is defined in Art. 1 Sec. 8, which states who will organize these militias and their purpose, which is to serve the government.
How was the formation of regulated militias made operational? It is explained in the Militia Acts, which required all white males of a certain age range, and with few exceptions, to obtain battle rifles and report for training.
Thus, the purpose of 2A is not merely to protect the right to bear arms but to use it to ensure mandatory military service, which is what happened via the Militia Acts.
The problem is that what Washington complained about persisted as armies became more professional and complex. The country learned that the hard way during the War of 1812, when they realized that a small standing army with militias would not be enough to deal with professional armies. It still took awhile, even when blacks were included among males to serve given a subsequent Militia Act. But it was the last one, in 1903, that led to the formation of the National Guard, and eventually made 2A irrelevant. As military forces became increasingly complex, the country had to rely on reserves trained in the same way as the standing army, with conscription employed in case more troops were needed.
Today, what is left of 2A is the Selective Service System, where male citizens are merely required to register, with the government given the option to conscript them if necessary.