What is the difference between PSD and squared magnitude of frequency spectrum?
The power spectral density describes the density of power in a stationary random process $X(t)$ per unit of frequency. By the Wiener-Khinchin theorem, it can be calculated as follows for a wide-sense stationary random process:

$$
S_{xx}(f) = \int_{-\infty}^{\infty} r_{xx}(\tau) e^{-j2\pi f \tau} d\tau
$$

where $r_{xx}(\tau)$ is the autocorrelation function of the process $X(t)$:

$$
r_{xx}(\tau) = \mathbb{E}\left(X(t)X(t - \tau)\right)
$$

This is only valid for a wide-sense stationary process because its autocorrelation function is only a function of the time lag $\tau$ and not the absolute time $t$; stated differently, this means that its second-order statistics don't change as a function of time.

With that said, if you have a sufficiently-detailed and accurate statistical model for your signal, then you can calculate its power spectral density using the relationship above. As an example, this can be used to calculate the power spectral density of communications signals, given the statistics of the information symbols carried by the signal and any pulse shaping employed during transmission.

In most practical situations, this level of information is not available, however, and one must resort to estimating a given signal's power spectral density. One very straightforward approach is to take the squared magnitude of its Fourier transform (or, perhaps, the squared magnitude of several short-time Fourier transforms and average them) as the estimate of the PSD. However, assuming that the signal you're observing contains some stochastic component (which is often the case), this is again just an estimate of what the true underlying PSD is based upon a single realization (i.e. a single observation) of the random process. Whether the power spectrum that you calculate bears any meaningful resemblance to the actual PSD of the process is situation-dependent.

As this previous post notes, there are many methods for PSD estimation; which is most suitable depends upon the character of the random process, any a priori information that you might have, and what features of the signal you're most interested in.