Both images you posted are of Pratt&Whitney J58 afterburning turbojet that was used on the Lockheed A-12 and Lockheed SR-71 aircraft. That engine ran particularly hot.
The engine was designed for operation at Mach 3.2. The efficiency of turbojet increases with speed, but only to a certain point and somewhere above Mach 2 it starts to decline. However efficiency of afterburner continues to increase, so this engine was designed to operate continuously with afterburner and to generate higher fraction of power in the afterburner than other engines.
The afterburner combustor liner was able to withstand temperature up to 1,760°C (3,800°F). The core of the flame was much hotter still, but a colder air was fed along the walls, like in all turbine engines, as explained here. The engine was also cooled by incoming fuel similarly to how rocket engines are.
Additionally, at the top speed, the compression heating as the air was slowed to subsonic speed in the inlet heated it to over 400°C (800°F) at the compressor face already. Since in the static test the air was not that hot, the engine might have actually ran a bit colder in the test than in normal operation.
This was however specific to this one engine. The compression heating is negligible at subsonic speeds and grows faster at higher Mach numbers. Most supersonic aircraft fly around Mach 2, where the effect is already noticeable, but not nearly as pronounced. For most engines, they run at roughly the same temperature in test as they do in normal operation. It just isn't as high as in this special case.