Because the rulers did not give a damn about the people.
The system fell down when they tried to improve it, to give hot water all the time. Gorby did not realized that the if he shakes the system it will fall down. It was not the catatonic leadership that brought down the system but the young, bright and energetic reformer. I'll love him for ever for his fortunate idealist error.
If the financial problem was the only one the SU would still be around. And the space program was cheap compared with the size of the Army and KGB, the war in Afghanistan, stupid foreign policy (at one point SU was supporting both sides in an Ethiopia-Somalia war), excessive donations that kept alive entire states (Cuba, N. Korea, Vietnam etc) insurgents (almost around the world) and parties (even in richer countries).
And as N Korea reminded us space technology started with V2. Sending a satellite in orbit it's the same like sending an ICBM. Large parts of the costs for all space programs were and are supported or done directly by the military.
The Apollo programs were the only time when the Americans beat the SU in the space race. After that they started the failed shuttle program that was much more expensive then rockets, so the soviets recovered the spotlight with the Salyut and Mir space stations. It took 30 years and several accidents for NASA to admit the failure of the shuttles while the soviets were so accustomed to copy the US that they made their own shuttle, Buran, that had just 1 flight but took off and landed without crew.