You’re talking about “The Doomsday Machine”. It sliced up planets and digested the bulk of each for power, leaving behind a lot of “small” rubble, however. Kirk nuked it from inside. (That probably created a lot of debris too, even tho’ the hull of the thing was not destroyed.)
One of ST’s best episodes, IMO.
That episode absolutely terrified me as a kid.