They were admitted as part of the "Missouri Compromise". Missouri wanted to be a state, but Missouri allowed slavery. Allowing another slave state into the Union would've tipped the delicate balance in Congress in favor of the slave states. So Maine, which was part of Massachusetts at the time, was separated off and made into a new Free State (that is, a non-slavery state) to balance against Missouri, which was allowed to finally become a state.