Everyone has said how it was done, both in the answer and the comments, so I know I am not adding anything new.
Aside from, this is a behind the scenes on how the Miranda class was blown up on set for the effect:
Behind the scenes: - no less than three attempts at blowing up models
Result: -
And here is a description of blowing up the Enterprise, old school miniature-blown up:
At the time (ST:TNG) , the standard technique was to superimpose footage of an explosion over stock footage of a physical studio model of the ship in post-production.
In this case, four break-away models were filled up with pyrotechnics, and blown up while shooting from multiple angles.
Typically, the debris of such models was discarded after use, but in this case the debris was gathered up on a hunch by Effects Supervisor Gary Hutzel. Hutzel recalled, "[W]e blew up a model for the Enterprise, by dropping it from the ceiling of the sound stage toward a high speed camera while timed charges went off to blow it up in mid-air. I went around with a cardboard box and picked up all the pieces of the model I could find, because I knew they would come in handy someday."
The debris was later reused for the destruction of another Galaxy-class vessel, the USS Odyssey, in the DS9 episode "The Jem'Hadar".
Notes:
- superimpose footage of an explosion over stock footage of a physical studio model of the ship in post-production - is cheaper, you do not pay to build a new model to blow up, pyros, cost of time, etc - stock is pre-paid and pre-filmed, ready on those tapes to drop in on the timeline.
- As seen in the YT footage, in almost every case regarding blowing up in space, you shoot from below to hide the effect of gravity. From below it looks like it explodes in every direction.
- You shoot in high speed so when you play back, it is in slow motion. From the old days of miniatures, there was a trick to it:
time taken for the miniature object to travel an equivalent distance (proportionately reduced distance) should be equal to the time taken for the real object to travel the actual distance
ie.
When a real object falls from a height of 100 meters, it takes about 4.5 sec. to reach ground. If miniature replica is 100:1 version, fall from 1 meter height will be for the duration of only 0.45 sec. Unless miniature-fall also occupies screen time of same 4.5 sec., the viewers do not believe it is the real object’s fall.
https://memory-alpha.fandom.com/wiki/Cause_and_Effect_(episode)