James Madison really screwed up with the wording of the 2nd Amendment. It seems to be a sentence with two unrelated independent clauses.
Depends on whether you read the version passed by 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.Or the version sent to the States for ratification:
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.Without the extra comma, the text is clearer. In any case, don't blame Madison alone. His original version read:
The right of the people to keep and bear arms shall not be infringed; a well armed and well regulated militia being the best security of a free country; but no person religiously scrupulous of bearing arms shall be compelled to render military service in person.