The Confederate battle flag is not, and never has been, the state flag of South Carolina. They have a blue flag with a crescent moon and a palmetto tree. South Carolina used to fly the Confederate battle flag from the top of the state capitol, on the same staff but below the state and national flags. Due to controversy they have moved the Confederate flag from the top of the building, but they still fly it on the capital grounds, in a discreet location. In the early 1960s Georgia redesigned their flag to incorporate the Confederate battle flag as a part of the design. This was widely perceived as a slap at the Civil Rights movement and was controversial for years. There was pressure to go back to the previous design, which shows how little it was understood because the previous design incorporated one of the versions of the Confederate national flag.
The flag you see today is a soldier's flag. It was designed because the Confederate national flag looked a lot like the US flag and you could not tell them apart easily on a smoky battlefield. The only place it was used was as the regimental flag of army units. The national Confederate government had three different designs for its flag.
Some people who fly the Confederate battle flag in the south are trying to commemorate their ancestors who fought in the Confederate armies, and make a statement about their heritage. Others are trying to make a racist statement. The first group wishes the second would keep their hands off the flag and not make it into a symbol of racism.