The Constitution doesn’t require a well-regulated militia - it simply says the right to keep and bear arms shall not be infringed. The militia is mentioned as a reason, not a condition.
It clearly says a well regulated militaries is necessary for the security of a free state. You can dither on whether the Constitution establishes a secure state or a free one, but the syllogism is there
The militia is mentioned first, but I’m not an English major who is able to parse old sentences. The militia is “necessary” so they need to know where the, erm, candidates are located and what they pack.