I’ve always understood (from constant debates about firearm restrictions) that it was intended to guarantee citizens the right to protect themselves from government forces (“a well-regulated militia”).
But it occurs to me that it might have been intended to prevent any interference in controlling slaves, i.e. so that white prior could always have supremacy of violence over slaves. Basically, I wonder if—as originally written—it was intended in part to protect the institution of slavery (same category as the 3/5 rule).
More can always be said, but this older answer might be of interest for you.