The state militia were originally intended to serve as the reserve forces of the United States Army and Navy both. As such they were descended from English "fencible" regiments and the medieval fyrd.
Militia units were organized on a community basis, and the officers were either chosen by election or by political appointment. This system, which encouraged raising new units rather than training and providing replacements for existing units, was very inefficient but managed to survive into the early 20th century for mainly political reasons: there is a traditional dislike for standing armies in American culture, and maintaining part-time armies is obviously cheaper than having soldiers on the payroll full-time.
Despite tradition, Army officers succeeded in gradually bringing the militia more under Federal control, stipulating regulations and organizational requirements accompanied by increased money from Washington for drill pay and new equipment; the militia was eventually redesignated the National Guard, which is what it's known as today.
At the same time, it was recognized that once National Guard units were federalized, there would be a need for militia units to provide disaster relief, riot suppression, and other civil defense tasks. State governors therefore organized new state militia units to fill this need.