If you are not using a CASIO brand sustain pedal, your pedal may have the opposite polarity. It will sustain when the pedal is not pressed, and remove the sustain during the pedal is pressed.
If you use a CASIO sustain pedal, it will only sustain during pressed. Many current CASIO instruments (such as Privia models) can automatically detect the polarity of a sustain pedal.
To ensure that the detection is correct on these models, firstly the pedal is connected to the appropriate jack, then the power of the keyboard turns on without touching the pedal.