It is not an explanatory clause in any way. It is a requirement that the government maintain a militia and consider and use it as the primary first defense of the security of the state. It is a compound sentence. It could even be considered a running-on sentence, where the author communicated two unrelated topics separated by a comma or semi-colon rather than a period.
Five different States included in their statements/documents ratifying the Constitution that it was done so on the agreement that there would be an amendment protecting the right of the people to keep and bear arms.
New Hampshire's was stated in the simplest of terms:
Congress shall never disarm any citizen, unless such as are or have been in actual rebellion.
The other four that demanded the right had variations on this, with some including even more differing ideas in the same sentence:
That the people have a right to keep and bear arms ; that a well regulated militia, composed of the body of the people, trained to arms, is the proper, natural, and safe defence of a free state.
Notice the order of the two statements: The right to keep and bear arms first and the militia clause, clearly stating that the militia is a mandatory part of the defense of a free state, as the second clause. Was the right to keep and bear arms explanatory of, the reason for, the requirement that the militia be composed of the body of the people, trained to arms, and be the natural and safe defense of a free state? Of course not.
The biggest mistake modern lawyers, legislators, Courts, and even the Supreme Court Justices, make is to attribute today's grammar rules, standards, practices, and even mistakes, to the writing style of the late 18th century. Instead, they need to look at other writings with similar constructs, logic, and statements, to understand how things were written at the time.
James Madison and his committee had to look at all of the proposed or demanded amendments and consolidate them. When states or other authors said the same thing but with different words or formatting or grammar, he had to consolidate that into a common statement. He consolidated the various statements into the 2nd Amendment, with some parts of the statements also going into the 3rd Amendment and some not making the cut from committee or Congress.
That, in editing, Madison reversed the order of the two statements is not in any way indicative of an intent to change the meaning or intent of the two statements. This is proven by the fact that every one of the five states, plus others, ratified the 4th proposed amendment (which became the 2nd Amendment).
Had the thing that those five states demanded, even as a stated condition of understanding in their ratification of the Constitution itself, been stripped by what became the 2nd Amendment, they surely would never have ratified that amendment. That they all five ratified the Amendment proves that, in the minds of all of the State Legislatures voting on the Bill of Rights, these statements:
That the people have a right to keep and bear arms ; that a well regulated militia, composed of the body of the people, trained to arms, is the proper, natural, and safe defence of a free state.
Meant EXACTLY the same as:
As voted out of Congress:
A well regulated militia being necessary to the security of a free state, the right of the people to keep and bear arms shall not be infringed.
Which meant EXACTLY the same as:
As Ratified:
A well regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed.
The word games between those three, played by the lawyers, the States, the gun controllers especially, the Courts and even the Justices of the Supreme Court are all self-serving by each.
There were multiple scribes who took what Madison edited, and copied it for Congress. When Congress passed it, multiple scribes copied from what Congress wrote to make copies for the States. That's why there are differences in what Congress received from Committee, what they voted on to go to the States, and what the States ratified.
In fact, considering the complete proposed Bill of Rights as a whole, different States got different versions. Commas were added or removed; some scribes used semi-colons where a different scribe used a comma. Some copies used the word "and" in places where other scribes used the ampersand (&) in the same places. They didn't have computers to guarantee that everything was perfectly alike across the entire process.
But, what the words meant, and that they all meant the same to the Founders, to the entire Congress, to each and every State Legislature, and that a comma here or there didn't change the meaning in any way, and that the order of the two statements does not change the way, is ABSOLUTELY proven by the fact that no one at all in the Congress or the State Legislatures challenged any of these differences at the time.
What many today call the prefatory clause is not a prefatory clause at all. It is a distinct and separate requirement on the government of the United States.