I've been recently looking at some 18th century documents, and I've been struck by how common this phrase and its cousins were throughout the 1700s. It certainly wasn't just an invention of the Revolutionary Era; for instance, a New York statute of July 24, 1724 was entitled "An Act for Settling and Regulating the Militia in this Province, and making the same Useful for the Security and Defence thereof, and for Repealing all other Acts relating to the same," and began:
Whereas an orderly and well disciplin'd Militia is justly esteemed to be a great Defence and Security to the Wellfare of this Province ....
(Spelling from a 1726 edition that I found in a proprietary database; the link I give in this post is to a 1894 edition.) The Act proceeded to define the militia as "every Person from Sixteen to Sixty Years of Age, residing within this Province" (though this might have been understood as being limited to men, and possibly free men); to provide how the militia was to be equipped; to mandate musters; to provide for the promulgation of articles of war; to provide for penalties for those members who didn't comply; and the like.
I express no opinion here about how this bears on Second Amendment debates -- I just want to highlight that the prefatory clause had a well-settled and familiar history to the Framers.