Its real purpose was to ensure that the fledgling country which did not have a standing army would be protected by armed militia's.
******************************************************************
Revisiting the Messy Language of the Second Amendment
https://daily.jstor.org/revisiting-messy-language-second-amendment/
The longstanding debate over these words boils down to this: did the founders draft the second amendment as single meaningful text, in which all parts provide meaning in the same context, or is it actually in two puzzlingly separate parts, the first “militia” clause being kind of a blithe hand wave, with the “bear arms” clause being more crucial? Furthermore, if the phrase “bear arms” had a primarily military meaning, this makes a big difference as to whether the second amendment protects the people’s collective right to certain arms, as part of a well-regulated militia, or an individual’s right to have any firearms for no reason at all.
Textualists are all about the text, except, it seems in the 2008 Heller opinion. The decision ultimately decided that only the last clause really mattered, with the first being merely
“prefatory, a bit of constitutional throat-clearing”, as it’s been described, that—astonishingly—has no real bearing on the second, more important clause.
Nelson Lund, a legal but not linguistic expert, argued that “the Second Amendment has exactly the same meaning that it would have had if the preamble had been omitted, or indeed if the preamble is demonstrably false.” Under this modern reading, it’s curiously the only amendment of its kind written with an unnecessary decorative preamble.
But eighteenth century readers with classical educations under their belts would have been very familiar with Latinate absolute constructions used in long, Ciceronian-style sentences, which in this context crucially seems to provide a causal reason for why such a right is protected, as though it were written “Because a well regulated Militia is necessary to the security of a free State, the right of the people to keep and bear Arms shall not be infringed.” That is, there may be a right to “keep and bear arms”, but that that right exists under certain conditions.