It was for real in TOS Let That be your Last Battlefield though. And the Nostromo in Alien had a self destruct mechanism too. But the Star Trek one is kind of a special case - if you power your ship with antimatter, then a self-destruct mechanism is probably all in software, and maybe a guy with a wrench to open a mechanical safety or ten - you’ve already got all the explosive power you need.