Well, canon Trek has obviously written self-destruction right into the Federation’s starship design philosophy. So, I can’t argue that. However, it still seems out of place to me for a number of reasons that make sense to me:
The primary reason is that I cannot believe that it would ever be necessary to self-destruct a Federation starship.
You may say that the captain must prevent classified information, technological information, and defensive information falling into enemy hands.
So, why destroy the entire starship? Just destroy the information. Furthermore, you don’t need a starship for that information, you just need its captain or the right person. Should the captured captain self-destruct too? That would be a Klingon thing to do in the form of fighting until he were killed, if possible. A Federation captain would just endure his refusal to give up information easily. That way, the enemy can learn something about the Federation that it can respect.
You may say that the captain must prevent the physical ship itself falling into enemy hands because they might examine it and reverse-engineer its technology for their own benefit, or they might discover its weaknesses and try to use them against the Fleet, or they might try to make use of the ship itself, which would be the most practical thing to do with it.
I’m not suggesting that a captain should just give up and easily surrender to the enemy or make it easy for them to take his ship. Why destroy the ship, though? By the time the enemy could unlock access and gain control, defend it all the while trying to bring it to their starbase, learn something new by examining it, develop their own prototype of the learned technology, conduct a production run, make the useful technology their own—all its secrets would be old news by then and they would probably already have something better on the go. Federation starships, which are not warships, should not represent the latest and greatest assets. They may be the latest and greatest production assets but not the best you could produce. A ship may be the most advanced in the Fleet, but that does not make it the pinnacle of your technological prowess. That would be reserved for prototypes and drawing boards that we never know about until it is already old. Besides, there are better ways to learn enemy secrets than capturing a starship with built in obsolescence. You just need to ask the right people and reward them accordingly.