A discharge pipe in the wall CAN meet code requirements, but it depends on the prevailing code of the jurisdiction, the location of the ultimate discharge of the pipe, the number of elbows to get there, the height of the discharge above the ground, whether or not the climate is subject to freezing temperatures... a number of different factors.
I've had the same situation... where the discharge pipe was already built into the wall but stubbed out of the wall too high for the new water heater. The original water heater had the T&P on top. That was what the builder had installed in the 1970's. Then, when that water heater was replaced in the 1990's, the T&P was on the side, and somewhat lower than the discharge pipe outlet pre plumbed through the wall. But the installer of that water heater simply soldered up a glob 90 degree fittings and stubs to eventually bring the discharge of the T&P UPWARD toward the pre plumbed discharge pipe in the wall, because this particular jurisdiction PROHIBITS T&P discharge into a pan.
Ironically, the adopted code in this jurisdiction also prohibits uphill drainage and the inherent, even if inadvertent, "P traps" incorporated into the T&P line from the elbows and short lengths of pipe needed to meet the higher stub out of the wall, because hard water deposits can calcify and crust up the P Trap, blocking the discharge path. But the inspector either didn't catch that flaw, or the person installing that replacement water heater didn't call for inspection.
Needless to say, while that second water heater was very well maintained by the homeowner, with new anodes installed every 5 years, recorded in writing right on the side of the water heater, as well as annual flushes and drain downs of the tank... eventually that P trapped T&P discharge did crust up, and became constricted enough to cause the water tank to leak elsewhere. No expansion tank either.
That's when I came in, once the heater sprang a leak. The in house closet location of the water heater tank, significantly away from any exterior walls, sort of dictated the use of the pre plumbed discharge piping already in the wall, routed to the outdoors. I verified that the outdoor discharge was acceptable and safe, and then verified that the plumbing was clear and unobstructed from the heater location to the exit. I used compressed air, as well as full flow water (with a temporary fitting attached to the stub) for the flow verification. There were less than 4 elbows in the 3/4" copper run as well.
However, I did open up the wall, and cut down the discharge pipe, stubbing it out again sufficiently below the average height of 40-50 gallon water heater with side outlet T&P valve so as to eliminate any potential P trap in future water heater hook ups, and maintain gravity drain.
It was significantly more work to cut into the wall, and re install sheetrock, tape, mud, sand, texture, prime, and paint... because once a wall is cut into, then another code kicks in regarding insulating the first 5 feet of hot and cold piping to and from the water heater. So the hole was two stud bays instead of just one, and had to extend down below the fire blocking. But that was the only way to do the job right, because the perimeter grade around the house was higher than what a floor drain could have been plumbed to.
With this recent real world example in mind, I would suggest to the OP to consider cutting into the wall where the discharge piping is plumbed, and cut down a foot or two of the vertical stand of the discharge inside the wall, and stub it out lower. Patch it all up and then a hard pipe downward gravity drain can be accomplished.