Who the militia is is irrelevant, the amendment states that the "right of the people" is not to be infringed, not the right of the militia. The preamble states that the right is protected because a well regulated militia is necessary, but the grammar of the sentence does not restrict the right to the militia.
If their was another amendment which read "A well read electorate being necessary to maintenance of a free state, the right of the people to keep and read books shall not be infringed" it would not be OK to ban those too young to vote or not registered to vote, who are not part of the electorate, from keeping and reading books.
The preamble states that the right is protected because a well regulated militia is necessary to the security of a free state.
Interesting to note that the preamble does not state that the right is protected because a well armed citizenry is necessary to the security of a free state.