NASA has a page with lots of info about their range safety program: https://kscsma.ksc.nasa.gov/RangeSafety
And yes the rockets had shape charges in each stage which can be activated to destroy the rocket in a controlled fashion. If you have a rocket gone haywire, it's better to jettison the crew capsule to safety and do a controlled demolition, to prevent the rocket from flying out of control and crashing into structures or people on the ground.
This is also why rocket launch sites tend to be coastal locations with ocean to the east - there's a lot less valuable stuff under their flight path.