Spectrum in real life with Spectrum in theory
why does this power measurement (which is an instant function of time)

It's NOT a instant function of time.
For example instantaneous power of a sine wave is
$$ p(t) = x(t)^2 = A \cdot cos^2(t) = \frac{A^2}{2}(1+cos(2t))$$
You have to apply some amount of time averaging to get rid of the $cos(2t)$ component and that's what all spectral analyzer do.

: if I stop the input signal, the spectrum becomes 0) ...

Not instantaneously. Since there is time domain averaging involved the power measurement can only change at a finite rate.
In general there is an &quot;uncertainty principle&quot; at work here: the higher the spectral resolution, the slower the system can react or track. For your first implementation, that is determined by the bandwidth of your demodulation filter. The smaller the bandwidth, the slower the output will change.
If you use a Fourier Transform based analyzer, this will be determined by the length of the (finite) time domain window you apply the transform over.

why does this power measurement ... coincide with the theoretical power spectral density |X(f)|2

It doesn't. All physical measurements are approximate in nature. They all have a margin of error, tolerance, repeatability variance etc. You can't measure anything exactly, but only &quot;good enough&quot; for your specific application&quot;.
You also need to define what exactly you want to measure within the context of your specific application and requirements. You don't need the exact power spectrum of an infinitely long signal, since infinitely long signals do not exist in nature.