It's a little inconsistent. Season 1 had the clearly intelligent "Salt Vampire" created treated like a Monster of the Week, while a little later, they actually took the time to talk to the Horta.
The Salt Vampire was a legitimate threat to others. Kirk was well within his rights to kill the Gorn captain, considering how the Gorn attacked a settlement, but Kirk decided on the Advanced Trait Of Mercy.
For their part, the Gorn believed their space had been invaded by the Federation and were merely protecting their territory. It has to be remembered that this was a first contact situation. The motivations of the Gorn were totally unknown until the Gorn captain and Kirk were forced to engage in combat. Additionally, in the original script, it would have been revealed that the Sufficiently Advanced Aliens would have killed the winner of the contest along with his ship, since they would have represented a potential danger.
In "Measure Of A Man," he is the subject of a hearing by the Judge Advocate General of Starfleet to determine his legal status: is he property or a person? The judge mentioned that they were "dancing around the basic issue -does Data have a soul?", which she concluded could not be proven or disproven, just as it could not be proven or disproven for humans and other organic sentients.
Later episodes on the topic featured Data defending the right of other artificial sentients to live, and the question of Data's "daughter," Lal and his parental rights concerning her.
The episode The Quality of Life dealt with it as well. A scientist invented "Exocomps", droid-like multipurpose tools with sophisticated AI. Occasionally an Exocomp would start to exhibit odd behavior, such as disobeying commands that would put it in danger. This leads Data to suggest that the Exocomps are becoming self-aware. Their inventor disagrees and wants to erase their memory and start over. The episode treats the question seriously and concluded that there was no easy answer.
In "Inheritance" Data meets his mother, Juliana Tainer (formerly Juliana Soong). It later turns out that she is an android too, created by his father to appear totally human and with the copied memories and personality of the original Juliana (who died after slipping into a coma), but she is unaware of this fact. When Data accesses the holographic message his father left in Juliana's positronic brain and confronts him about not telling her what she really is, Dr. Soong makes his feelings on the matter clear:
Data: Then... you do not believe she should know the truth?.
Dr Soong: Truth... the truth is, in every way that matters, she is Juliana Soong.
Star Trek: Voyager explored the rights of the holographic doctor, including his right to have a say in his treatment. In one episode, rather than delete months of his memory (and personality), Janeway eventually allowed him to work through psychological problems that could have kept him out of Sickbay for weeks or even months — despite the risk this might pose to the crew. Janeway had initially decided to just reboot the Doc, but changed her mind upon talking to Seven of Nine. When Janeway pointed out that the Doc was more like a replicator than a human, Seven pointed out that she, too, being Borg, was composed of parts not unlike the replicator, and wondered whether Janeway would eventually override her free will as well.
In one episode of Voyager, the Doctor had written a novel and submitted a draft, pre-editing, that the publisher thought was delightfully salacious in the way it seemed to impugn the Voyager crew, and promptly started distributing. The Doctor sued to have it stopped; the publisher argued he couldn't sue because he wasn't a person. This editor was waiting through the entire episode for someone to look through Starfleet's records and discover that an artificial being that has intelligence that can improve itself, have sex, and express itself artistically is a person, because Data was found to be so in the second season of The Next Generation. This was done again with polymorphic tools called Exocomps that were proven to have gained low-level intelligence and were excellent problem-solvers. Admittedly, ruling that the Doctor was a person would open the door to ruling the same for Mark I EMHs all over the Federation, who had by then been consigned to manual labor; meanwhile, there was only one Data. It gets even less justifiable when you consider that the Doctor is essentially a Projected Android.
Also, all other holograms. If the world recognizes the fact that the Doctor achieved full sentience after being left running for long enough, suddenly using a Projected Man the way all the TNG-era Treks do becomes the stem cell debate times a thousand. Using them as novel characters (let alone combat practice) would be right out. As such, Starfleet recognizing the Doctor as a person is never going to happen. Ever. Interestingly, it does seem that your average Trek hologram can become sentient if given the chance: Just ask not only the Doctor, but the hologram Hirogen prey from Flesh and Blood, the woman we thought was Dr. Zimmerman's daughter until Deanna found she couldn't read her, Vic Fontaine, Professor Moriarty, and on and on. Trek hologram use is seriousMoral Dissonance. And, since A.I. Is a Crapshoot, it bites them in the hindparts enough that such use goes beyond Genre Blindness and into What an Idiot territory.
Carried even further, the right to vote was mentioned inside the episode. The Federation quite sensibly has no desire to extend suffrage to an easily-replicated computer program that can be given whatever personality, desires and values the programmer wants it to have (and have its Ethics directory deleted with a push of a button). For what it's worth, the final decision is a bit of a subversion of the usual outcome: the court decides that the Doctor is not legally a "person". However, in a Meaningless Villain Victory twist, although the court declines to rule on whether he qualifies as a "person", he does qualify as an "artist", and therefore is granted ownership rights to his holonovel anyway. There have been instances of respecting non-Doctor holograms, though, such as Janeway putting the ship at risk to save the holographic town of Fair Haven. Except that the town's achievement of self-awareness was treated as a malfunction to be fixed—a malfunction specifically caused by running too long, the usual cause of sentient holograms.
Who says all holograms are created equal? The Doctor is obviously very powerful and sophisticated, but a combat practice hologram could be little more "intelligent" than an AI bot in a video game—a completely unliving set of routines with no consciousness or sensations.
Entire story arcs are dedicated to analyzing the status of holograms... and never really reach a satisfactory conclusion. Janeway actually breaks the Prime Directive and buys off a entire race of Egomaniac Hunters with hologram technology; they refine and develop the technology so the holograms feel pain, fear and rage. This makes AI a crapshoot with loaded dice; they rebel and start killing every one of them they can find. The Doctor sympathizes with them, but a truly disturbing conversation ensues where the "flesh and blood" characters blithely discuss modifying their programs in ways that could only be performed on organics via brain surgery. The Doctor defects, and it looks like a Wham Episode awaits... then they render the whole plot moot by showing that the rebel holograms have gone Colonel Kilgore; they kill organics to "rescue" holograms no more intelligent than tricorders, then strand the hunters on a toxic moon to hunt them down themselves. They're rescued, the Doctor is forced to eat crow, and one of the "nice" hunters decides to pretend he's dead and "fix" the holograms.
In a Mirror Universe episode of Enterprise, this trope is played with to an almost sadistic degree. The viewers get to see the crew torture an insect-like Tholian by lowering the temperature in its prison cell to uncomfortable depths. (Tholians naturally exist at extreme levels of heat and pressure.) To really drive it in, we get a close-up view as the creature explodes. What makes it worse is that the Tholians are fighting against the Empire and their cruelty towards non-humanoids in this Universe (for the record, there's no closeup as a helpless humanoid Gorn gets shot half a dozen times). Given the lurid special effects during the torture scene, this became a deeply Family-Unfriendly Aesop for many.
Since the crew are villains in the Mirror Universe, nothing they do is an Aesop. As for the producers being less willing to show human(oid) giblets than an alien shattering... the fact is that Most Writers Are Human and most viewers as well, and it would have been more disturbing to most (if it got through the censors at all.) A Gorn-fillednote Gorn as in the trope, not the lizard guys horror series is something Star Trek does not aspire to be; it's got enough of a Nightmare Fuel page as it is! In-universe, the mirror crew treats humans, Rubber-Forehead Aliens, and Starfish Aliens as being exactly the same - easily disposed of.
The treatment of duplicates in Trek is even more schizophrenic. Just to examine two episodes featuring Riker:
In Up the Long Ladder, the crew encounters the Mariposans, a planet whose hat is reproduction through cloning, but the replicative fading (a real phenomenon) is starting to catch up to them. They rip off DNA from Riker and Pulaski. When this is discovered, Riker and Pulaski (a doctor!) find the lab and blithely massacre the duplicates. Riker states that the clones' existence "diminishes" him.
The clones that Riker destroyed were only partially formed things, looking diaphanous and only vegetatively alive. Despite being somehow adult-shaped. Which would make it more akin to abortion, but Trek wasn't going to touch that.
In Second Chances, the crew discovers another Riker (who comes to use "Thomas", his middle name), created unknowingly by a transporter accident early in Will Riker's career. Even though they clash, Tom's personhood is never questioned (Will treats him as the twin brother he never knew and saves him!), and he eventually comes to be treated as if he were a newly awake coma patient, leaving to build a new life.
Though the accident that created Thomas simply sent equal parts of Riker to two different locations, so that they were both equally the "real" Riker. The clones, on the other hand, were just copies of the originals, though that doesn't diminish the Moral Dissonance of killing them.
Especially when one remembers that in the Deep Space Nine episode "A Man Alone" Odo actually specifically states that killing your own clone is still murder.
The clones in The Next Generation hadn't hatched yet, and thus their actions were probably closer to abortion than murder. The clone that Odo mentioned was fully sentient by the time he was out and about. Besides, Odo enforces the laws of Bajor rather than the laws of the Federation.
And, you know, the law could have changed between the episodes. With new species and new brands of science being discovered every year, Federation law probably changes swiftly.
The main villains of Deep Space Nine are the Jem'hadar, genetically-engineered super-soldiers. They're bred to be obedient and violent, and there are an awful lot of them. Their main purpose is to get killed in hand-to-hand battles. Every once in a while we meet an individual Jem'hadar who acts almost like an ordinary person, and our heroes pause to consider their humanity. Of course, since the majority of the Jem'hadar encountered by Our Heroes are enemy combatants, the question is largely academic.
There's an interesting mission in Star Trek Online. It deals with a Ferengi wanting a hologram program to complete his collection. He asks you to persuade another person to give him a copy. However, it's not a humanoid being, but rather a photonic being who holds the program. The rest of the mission is a small part about seeing photonic lifeforms as sentient. So in the future of the Prime timeline, photonic beings do gain some rights. Come to think of it, you can get a photonic bridge officer as well.
One of the loading screens mentions that the Doctor ended up driving the issue to the Federation Supreme Court, which did indeed decide that he was a person. It may only apply to some holograms, of course, since the Doctor was specifically noted as being designed with unusual learning and adaptation capacity for a hologram (a trait that he, one way or the other, shared with the other sentient holograms showed).
In one Trek novel by Diane Duane, Kirk is chatting with a friendly AI named Moira, who lampshades this trope:
""Your intelligence is just electrons," she said, "the same as mine. You're just electrons... the same as me. You always seemed too intelligent to be a protein chauvinist, Captain."