It is actually not that simple to ensure the proper gas speed in a gas turbine. In the compressor you want to limit the flow speed over the compressor vanes to the high subsonic range, so the inlet has to decelerate the flow down to approx. Mach 0.4 - 0.5. Less would mean less throughput and consequently less thrust.
This speed, however, is far too high for ignition. The fuel needs some time to mix with the compressed air, and if flow speed is high, your combustion chamber becomes very long and the engine becomes heavier than necessary. Therefore, the cross section leading from the compressor to the combustion chamber is carefully widened to slow down the airflow without separation (see the section below named "diffusor"). Around the fuel injectors you will find the lowest gas speed in the whole engine. Now the combustion heats the gas up, and makes it expand. The highest pressure in the whole engine is right at the last compressor stage - from there on pressure only drops the farther you progress. This ensures that no backflow into the compressor is possible. However, when the compressor stalls (this is quite like a wing stalling - the compressor vanes are little wings and have the same limitations), it cannot maintain the high pressure and you get reverse flow. This is called a surge.
The graph below shows typical values of flow speed, temperature and pressure in a jet engine. Getting these right is the task of the engine designer.
Plot of engine flow parameters over the length of a turbojet (picture taken from this publication)
The rear part of the engine must block the flow of the expanding gas less than the forward part to make sure it continues to flow in the right direction. By keeping the cross section of the combustor constant, the engine designer ensures that the expanding gas will accelerate, converting thermal energy to kinetic energy, without losing its pressure (the small pressure drop in the combustor is caused by friction and the Rayleigh effect). Now the accelerated flow hits the turbine, and the pressure of the gas drops in each of its stages, which again makes sure that no backflow occurs. The turbine has to take as much energy from the flow as needed to run the compressor and the attached pumps and generators without blocking the flow too much.
The remaining pressure is again converted to speed in the nozzle. Now the gas is still much hotter than ambient air, and even though the flow at the end of the nozzle is still subsonic in modern airliner engines, the actual flow speed is much higher than the flight speed. The speed difference between flight speed and the exit speed of the gas in the nozzle is what produces thrust.
Fighter engines usually have supersonic flow at the end of the nozzle, which requires careful shaping and adjustment of the nozzle contour. Read all about it here.