The Second Amendment is a relic of the world of American slavery. It allowed slave states to arm their own white militias to put down slave revolts w/out waiting for federal troops to arrive. This context should be understood.

While the Bill of Rights was being debated in August 1791 the Haitian Revolution began with a massive, bloody, slave revolt that featured terrible massacres of white French  residents. Ships brought word of the revolt to the US within a few days, and southern plantation owners would remain terrified by the spectre of similar revolts in the US for 70+ years afterwards.

Many southerners were skeptical that the federal government could protect them against slave revolts, and there was widespread suspicion that a standing army would become a tool of federal tyranny. The Second Amendment was the perfect compromise: it basically converted the entire free white population of the South into an anti-slave militia capable of very quick response to slave revolts.