The sentence means this:
A well regulated Militia, being necessary to the security of a free State, shall not be infringed.
The right of the people to keep and bear Arms, being necessary to the security of a free State, shall not be infringed.
The comma acts as an "and", to combine two different but similar rights