American white southerners (and white northerners for that matter) were scared out of their minds about the possibility of a rebellion comparable to the Haitian Revolution, which was contemporaneous with (edit: to clarify, took place during the ratification of) the Bill of Rights. https://en.wikipedia.org/wiki/Haitian_Revolution
A guarantee that “well regulated” militias under local control would not be taken down by the federal government was certainly related to slavery. Maintaining wealthy landowners’ power and protecting from slave revolts or other uprisings of disempowered people was perhaps the #1 purpose of those local militias.