system
Given the following post, respond as if you're commenting on Reddit:
human
[Star Trek] Why are surface to space planetary defenses not used?

Homeworlds have been attacked repeatedly, yet homeworlds seem to be remarkably lightly defended. Even the Dominion only had orbital defenses around Cardassia Prime. Legions of soldiers on the ground, but no surface to space weapon emplacements.

Earth is nearly entirely undefended as well. Earth has been repeatedly attacked. Attacks on Earth should almost be expected at this point, yet Earth still has no defenses to speak of. Going purely from memory, Earth has been attacked by the Xindi, by the Borg (at least twice), by a Whale Probe, and by the Breen.

The Xindi were building a planet-killer. Earth was attacked by the prototype, scaled down version, and then the full scale version was defeated only moments before firing. Later on, Earth was attacked by the Whale Probe in one timeline, and Nero's ship in the other timeline. Both were planet-killers. Yet in both cases, these ships were able to enter orbit entirely unopposed.

Has no one installed surface to space weapons? Shield generators and phaser banks located on the surface could tap into the entire planet's power grid. A homeworld, such as Earth, generates far more power than a starship. Probably more power than a whole fleet of starships. All of that power could be diverted to immense shield generators and phaser banks. Equipment on a starship has to be small and light enough to be portable. It has to fit on a ship. Planetary defense installations do not have those limitations. There is no limit as to how big, heavy, and powerful these weapons can be.

Or at very least, what about surface to space torpedo launchers? Tens of thousands of torpedoes could be fired, enough to rapidly overwhelm and destroy any attacker nearby.

Why are homeworlds so lightly defended even when homeworlds are attacked on a regular basis?
gpt
The first reason is resources. It takes a massive amount of power and facilities to protect an entire planet with a shield of any notable strength. Doing so for even one planet would be a massive undertaking and would not ensure its safety from attack.

The second reason is that a planet with a shield and/or surface weapons is a huge sitting military target. Star Trek ships can target, fire, and maneuver at FTL speeds. A planet can't actually move, maneuver a better firing solution, or even safely fire from all areas within its airspace. So while planetary weapons would more or less invite ships to shoot at the planet (causing massive amounts of destruction once any applicable shields fail) it doesn't actually give them a very good opportunity to fire back to defend themselves.

Sure, you could flood the entire sky with torpedoes, but your target can also just fly away from them, or fly back around at such an angle the shots start crashing into things you're trying to defend. 

Weapon stations mounted to the surface of the planet don't even have to be hit directly to be rendered useless or explode either. A ship can just attack the general area until the ground becomes unstable enough to topple the facilities. 

The third reason is that no one wants that kind of building in their back yard. It might sound silly when you're talking about the safety of the entire planet, but people are rarely interested in living next to a power plant, let alone a photon torpedo array carrying enough firepower to reduce the planet itself to space dust. The people of Earth in particular are pretty happy to have their lovely forests and happy little federation cities instead.

The fourth reason is that if someone surprises you the shield won't be able to be raised quickly enough to actually prevent them from knocking it out. Planetary shield generators and other defenses aren't difficult to locate and map during peace time and a shield can't be maintained 24/7 because it will trap everyone on the planet. All it takes are a few seconds to drop a cloak and toss everything you have at a ground target.

Heck, depending on the construction you might be able to just use a shuttle craft or planted explosives to knock one out.