The Voyager episode Tuvix deals with a transporter accident which combines the most annoying parts of Neelix and Tuvok into a single person called Tuvix. It deals with the ethical ramifications of having to kill Tuvix to restore Neelix and Tuvok. For once in Star Trek, there's no neat solution.
I'm going to go beyond the bounds of the question, beyond Star Trek, and reference the cryptically named New Outer Limits episode "Think Like A Dinosaur" which isn't about dinosaurs but the ethics of a matter transporter. Somebody happened to think dinosaur aliens would be cool. It takes a very literal interpretation that transporting is copying. You can watch it, it's not too bad. It's not Star Trek, but it directly tackles the issue.
The interstellar travel machine works by making an exact molecular copy of the travel called "jumper" at the place of destination, however the original human being is eliminated through incineration as to balance the equation. The transportation is aborted and Kamala [the transportee] is brought back to life before being incinerated, with a huge trauma for the pain and experience she went through. Later the Hanen says the molecular copy was succesful and orders Michael [the transporter operator] to balance the equation, which will mean killing Kamala.
Going beyond sci-fi, the ethical thought experiment associated with the transporter is The Swampman.
Suppose Davidson goes hiking in the swamp and is struck and killed by a lightning bolt. At the same time, nearby in the swamp another lightning bolt spontaneously rearranges a bunch of molecules such that, entirely by coincidence, they take on exactly the same form that Davidson's body had at the moment of his untimely death.
This being, whom Davidson terms "Swampman," has, of course, a brain which is structurally identical to that which Davidson had, and will thus, presumably, behave exactly as Davidson would have. He will walk out of the swamp, return to Davidson's office at Berkeley, and write the same essays he would have written; he will interact like an amicable person with all of Davidson's friends and family, and so forth.
Interestingly, this was proposed in 1987. Obviously Davidson was not a Star Trek fan. One camp holds that the creature which comes out of the swamp is not Davidson and has no causal relationship to Davidson, even if it acts indistinguishably from Davidson. It has no history, and is merely a coincidence.
The other camp says of course there's a relationship, the swampman was created based on Davidson's state at the time. If Davidson was different just before he was disintegrated, the swampman would be different. The idea that it's an extraordinarily improbable coincidence makes the thought experiment divorced from any useful reality.
Yet another camp says the whole thing relies on there being a mind/brain duality, the idea that "the mind" is distinct from the physical organ of the brain. They reject this and adhere to mind-brain identity, that you are a bag of chemicals and that's that. If the swampman is physically identical to Davidson, then it is Davidson.