The origin of the sub-terahertz (sub-THz) component of radio emission from solar flares, which is characterized by the increase flux with frequency in the 100-400 GHz range, is considered. On the basis of equations of 1D non-LTE radiation hydrodynamics we simulated the altitude distribution of the plasma density and temperature inside the flare loop caused by the interaction of non-stationary beam of accelerated electrons in the form of a triangular pulse with the chromospheric plasma. The FLARIX numerical code was used to calculate the dynamics of the flare plasma parameters at different heights which are compared with the RADYN numerical code. We found that the characteristic heights of the formation of sub-THz emission vary over a wide range with time for both codes. The main contribution to the sub-THz emission comes from the chromospheric and transition region plasma with temperatures of 104–105K.