If a Star Trek Transporter can remember the physical state of a person it transports from point A to point B, then why couldn't it heal an injured person it has transported back to their uninjured state?
Theoretically it can.
This was a large topic of discussion in the TNG episode Unnatural Selection (S02E07). In the episode, while quarantined on a shuttlecraft Doctor Pulaski contracts a disease that speeds up her aging process. While the Enterprise staff is coming up with solutions for saving her
...Transporter Chief Miles O'Brien gets an idea: they can use the transporter trace, a previous pattern when she didn't have the disease, to control the way she is reconstituted.
The problem ends up being that she has never used the transporter before, so they find her DNA on a hair follicle from her cabin and use that to reconstruct her pattern through the transporter.
Watch this episode and they go through a lot about using the transporters in the way you've suggested. They don't end up using the pattern trace since it doesn't exist, but they talk about it as a good solution. And they do end up using her DNA pattern and the transporter to heal her of the aging disease.
This was also done in the TAS episode The Lorelei Signal (S01E04), it just wasn't talked about nearly as much.
This presumably isn't attempted more frequently because of the huge risks associated with the process. In both episodes, they talk about the danger of it failing, which would cause the people's molecules to scatter in space. On Unnatural Selection:
Chief O'Brien says it will work, but it would be risky, since they will lose her pattern if it doesn't work.
On The Lorelei Signal:
Spock states that the odds are against them, 99.7 to 1. If it fails, their patterns will break up and scatter in space.
Because of the inherent risk, this seems to be a "nothing else will work and this is our only option" emergency solution. It's less risky to transport someone with a broken leg and have the medical team fix it. If they fail, at least the person wasn't transported out of existence and they're just left with a messed-up leg.
I can't remember which episode, but there's one that mentioned some one's pattern cannot be hold up in transporter more then certain time. It's said prohibited by Federation law. If somehow it does happen, whatever the reason, that pattern must be destroyed (so does the person itself).
Anyway just knowing there's an episode that tried to use transporter to cure someone disease with transporter. Guess it's "legal" if the intention is to save some one's live.
I remember an episode of Voyager in which they were holding usable biological patterns in a transporter buffer, and they could only hold it there for about a half hour or so, before the patterns would degrade. A transporter is essentially a giant replicator, and it's a well known fact that replicators can't reproduce complex organic matter. The way that I've always thought of it was that during transport, your body was streamed from location to your destination, much like a radio stream of the internet. We humans are so big that you couldn't possibly store people in the main computer's storage devices, so the buffers are put into place for a consistent read/write time. It would suck if you had to buffer while you were materialization.
I don't think the transporter system would have the time to make the bulk edits needed to say, remove the cancer from your body. Think of zip files, when you edit one file, you have to uncompress the entire thing, then recompress the new file. Voyager's crew managed to do the transporter magic trick thing maybe three times, before there was biological repercussions. You'd probably do more harm then good.
There are hints that the memory capacity needed for transporter patterns is massive even for future technology.
The assumption that all electronic memories are digital and essentially stable over an arbitrary amount of time, in the worst case by making a perfect copy (also, the assumption you can always perfectly copy them!), is newer than most canon-defining ST material.
In the 1960s, going digital when not needed would likely have been a somewhat absurd notion for an engineer even when imaging technology hundreds of years into the future.
--- What follows is real life electronics geekery, for comparison ---
Even in the 1960s to 1990s, finding unquantized ANALOG signals (that are subject to degradation in storage in some way or another) to be the most economic storage encoding was common. There were audio and video tapes, one-line glass-stick delay line memories in PAL televisions and VCRs, analog image stores like Radechon tubes or DVBST displays in professional applications (jam-proof RADAR, 1970s computer graphics terminals, fast data acquisition), long-persistence phosphors in radar CRT screens, bucket-brigade analog delays (in 1980s musician's delay units), analog CCDs (in high speed data acquistion), semiconductor based but ANALOG audio storage microchips (eg the ISD1016 series). All of these provided a MORE economic solution than quantizing and digitizing, then storing digitally on a medium that could have held more analog data, then converting back to analog, the data that needed storing. Note: quantizing = translating a real-life measure into something that can be expressed as a writable number. Not all digital signals are quantized (eg a PWM signal might not be), not all analog signals are truly unquantized (modern flash memory for SSDs and USB sticks often use a kind of quantized analog format internally).
Even many (not all!) real life digital storage systems rely on cancelling decay effects by regularly replacing the data with a perfect copy for the data to last. DRAMs used in modern computers do. Mass storage systems like HDD or SSD only do so accidentally and occasionally. Anything that can store a lot AND very fast is likely to need it. Unquantized data can neither be kept truly perfect for ANY length of time, nor can any copy of it ever be perfect (the ever-present noise will see to that).
Also, digitizing a very large amount of data will always give you a timing disadvantage - think of a real life camera sensor. While it can capture a, say, 12 megapixel (ca. 40 megabyte, assuming 3 channels a 8 bits) image at a 1/10000th second shutter speed (actually, most camera shutters don't work quite that way, but that is irrelevant here) - it is usually not capable of digitizing and transferring into memory all of that image in 1/10000th second (which would need a bandwidth of 400 gigabytes/second. Which would even today be an extra tall order, above what would be economical in the average camera). Using an analog signal would seemingly land you in similar trouble here - but in both cases the solution would be "use more parallel channels" (eg all rows or columns in parallel on a wire each), and working with analog end-to-end here could still prove the more cost effective solution if speed but not permanent storage was desired (say, 2048 100MHz video channels vs 2048 equally fast 8 bit flash or SAR ADCs. Both are nightmare fuel.).
In something (eg a living being) that moves internally on all levels, accepting timing skews by not imaging everything at the same time won't go well.
Even today, a system that would need short-term data storage capacity beyond what is possible/economic in a digital way would be likely implemented in an analog manner at the very frontend.
The transporter was utilized for medical purposes on several occasions... but this is not exactly a standard procedure as it takes energy, and during emergency situations, use of this approach might be limited due to systems possibly taking damage during combat, or some other crisis.
Technically speaking, the transporter already filters our a variety of biological contaminants from say an away team... however, we only see the transporter being used for medical purposes in rare situations with no other options available.
The TNG episode 'Unnatural selection' demonstrates that it would be possible to reverse ageing, but it requires a 'clean DNA' sample (one that was taken at a time when a person was young and healthy - in this case, these records would be easily stored remotely, or as transporter traces which can be regularly backed up and preserved in protected/backed up memory files remotely). Incidentally, such a procedure COULD also be used to technically repair massive internal injuries, diseases, etc... and it wouldn't require a long time of a person to spend in the buffer... only 10 to 15 seconds probably for 24th century technology... and we saw that dozens of people were held in transporter suspension for MUCH longer (for which the pattern buffers need to be modified/expanded).
Problem for Trek is that the writers come up with solutions to problems using technology that would render many of the 'drama' obsolete. Now, personally, to me this would indicate a proper advancement of an interstellar species which possesses such technology... and the writers would simply need to 'adapt' to these circumstances and write the story within that setting in that case... but as we saw, it was easier for them to simply 'write and forget' these things - which is downright shame.
Now, transporters won't always be available (Say during firefight, etc.), in which case, regular medical approach would still be used. But I don't see a reason by sickbays wouldn't utilize their own transporters which are separate of the main systems (therefore not easily affected). Plus, we saw on Voyager that a site to site transporter can be made into a fairly portable piece of hardware. There's no real reason why future sickbays might not use this approach for cases that are beyond regular treatments - but as I said, it requires power.
Otherwise, ageing can also be reversed by using stem-cells treatments as research from even decades ago demonstrated. Problem is, that TOS and TNG were not exactly made in a day and age of Internet where accessing a large variety of scientific data was as simple as today. In the 1960-ies and 1980-ies, data access would be far slower and rely on knowledge from individuals who were educated in these matters... and as we know, even specialists would contain a bare fraction of the information on a given topic, and would therefore not have knowledge of ALL information ever collected in any given field they might have specialized. Also, stem-cell research and application were blocked by fairly ignorant/uneducated humans in USA in the early days, so some controversy would likely apply to a TV program that was mainly made for 'family friendly audience' in the USA.
Now, personally, I think that Star Trek would need to be updated radically. Given our current technological knowledge and understanding, the 22nd century Trek would probably be WAY beyond what we actually saw (as Trek didn't exactly take into account exponential progress and subsequent returns as Ray Kurzweill suggests - he never commented on Trek, just that I am saying Trek didn't exactly integrate exponential progress that well into the series - The Federation would have been evolving even faster given no monetary system, free exchange of ideas, resources, etc.).
At any rate, we saw a wide array of regenerative devices in the 24th century. There is no real reason these devices couldn't be used to stimulate cell regeneration and de-age individuals from say 100 years to 25 or 30 even.
It is also possible that since we only saw a bare fraction of the Federation as a whole, that their medicine DOES allow biological immortality in perfect youth and health and there are people among them who underwent such 'treatments'... but that at least some people think this might somehow 'violate' some a notion of 'natural law'... or at least the characters we saw. It wouldn't be the first time Trek has for example Humans who had access to fairly old knowledge of their own species which they went to apply in practice without outside interference. I doubt the Federation would prevent de-ageing or see it as a violation of anything... but it might just not be commonly widespread by that time even though its available.
Though, in this case, the movie 'Insurrection' would need to be kicked out of canon (and not a bad idea either as the whole premise simply doesn't make any sense for any civilization that has Federation level of technology and knowledge).
Gene Roddenberry also apparently didn't like robots too much, AI in general or automation it seem... hence why Data was likely the only one and why it was 'next to impossible' to reproduce him (really? a species which has sensors and technology accurate to the subatomic cannot reproduce Data?... not likely). Plus some people suggested that Starships are made manually... which is ridiculous as space is dangerous and would require high scale automation (which is likely what the Federation implements anyway) in construction to make ships extremely fast and accurately.
Some ships might be constructed by hand if people choose to do so, but I imagine that for the most part, Starfleet vessels are made entirely through automation.
In this sense, transporters COULD be used for medical purposes.. we just don't see it in widespread use. For example, Starships have individual approaches in how they handle various situations... this also applies to individual SF officers.
The episode 'Unnatural Selection' is one of those stupid canon breaking episodes that should never have been resolved as it did.
The showrunners should have made the writers come up with a better solution to the illness Dr Polaski and the other scientists had. Using the transporter to cure the illness and make them young again was just plain lazy writing. It is a canon breaker because it makes curing someone sick a relatively simple task. As long as there is a pre sickness transporter trace then anyone ill, or even injured, can be simply run through the transporter and they come out perfectly healthy again.
Worse, it could also be used to restore someone to a younger age, making death obsolete. As long as you've got a trace from when you were younger, who wouldn't treat themselves to a yearly birthday present of going through a transporter and coming out a year younger again.
Even worse, it can be used to clone someone. All you would need is some energy and a transporter trace and out pops a clone of that person.
And even worse than that, it could be used to bring a dead person back to life. The dead could simply be put into the transporter and as long as there is a pre-death transporter trace they can simply be reanimated.
According to most official Star Trek resources the transporters are supposed to work like this; the person or object is scanned, then the molecules are converted into sub-atomic energy particles, these particles are briefly stored in the pattern buffer, then directed to a transporter emitter array, from there the matter stream is transmitted through a subspace domain to the destination, finally the energy particles are converted back into matter and the person or object rematerialises.
This means a sick person rematerialises sick, an injured person still needs medical attention, no one stays young forever, no clones, and the dead stay dead!
This is also why a person can't be stored in the transporter forever. The matter stream can only be held in the transporter buffer for a few minutes maximum. After that, the sub-atomic particles start to decay and the pattern degrades. If the pattern degrades too much the person cannot be rematerialisation fully and/or alive.
When the pattern has degraded too far there are only three things that can happen. One, it can be redirected back to an emitter and rematerialised as a cloud of individual atoms in space. Two, it can be left to decay into nothing inside the buffer. Or three, what is left can be rematerialised with a large amount of missing molecules. That means whatever is being transported will be 'incomplete'. An object would come with bits missing and a person would come out as a messy organic lump.
So the answer to your question is no, it cannot be used to heal an injured person. Unless of course, the story is being written by a lazy writer.