Simulations of coherent spontaneous undulator radiation in a waveguide demonstrate that the use of negative mass instability (NMI) for retaining longitudinal sizes of dense electron bunches, which are formed in laser-driven photoinjectors, allows one to increase power capabilities of a terahertz radiation source by many times. The NMI is realized in an undulator with combined helical and over-resonance uniform longitudinal magnetic fields due to nonisochronous longitudinal oscillations of electrons, whose frequencies increase/decrease with increasing/decreasing particle energy. In such conditions, an effective longitudinal size of the bunches can be preserved at long distance even at an extremely high electron density. Correspondingly, an energy extraction efficiency of more than 20% is revealed at a narrow frequency radiation spectrum, suggesting realization of a compact and powerful THz source.