Legal by the Constitution during their time that is
At the time of the Civil War, the answer to the question was uncertain. During the War of 1812, for example, some areas in the north-east explored secession at the 1814 Hartford Convention, and through to the 1850s, there was a doctrine of 'nullification' in which states asserted they could 'nullify' federal laws they thought were unconstitutional on the basis that the union was a voluntary compact between states (which may have served to temper secessionist impulses). Nullification was struck down by the US Supreme Court in 1859 in Ableman v Booth.
The question of whether secession was legal was only resolved legally in 1869 by the US Supreme Court definitively in Texas v White, in which it was held that secession was unlawful.