That's only true if the pde is linear.
Consider the equation
U_{xx}= U_{tt}
with boundary conditions U(0, t)= 0 and U(L, t)= 0 and initial conditions U(x, 0)= f(x), Ut(x, 0)= 0.
If U(x,t) and V(x,t) are two functions satisfying that equation and a and b are any two numbers, then (aU+ bV)_{xx}= aU_{xx}+ bV_{xx} and because U and V satisfy U_{xx}= U_{tt} and V_{xx}= V_{tt}, we can write that as aU_{tt}+ bV_{tt}= (aU+ bV)_{tt} so that (aU+ bV)_{xx}= (aU+ bV)_{tt}. That is, aU+ bV satisfies the same differential equation.
If we let U= T(t)X(x) (separate it into a function of t only and a function of x only) we get
TX''= T''X
which we can rewrite as
\frac{X''}{X}= \frac{T''}{T}
Since the left side depends only upon x and the right depends only on t, in order to be equal for all x and t, the two sides must be equal to the same constant.
That is,
\frac{X''}{X}= \frac{T''}{T}= \lambda
for some constant \lambda.
That gives us the two equations X''= \lambda X and T''= \lambda T.
Further, U(0, t)= X(0)T(t)= 0. Either T(t)= 0 which would mean U(x, t)= 0 for all x and t, or X(0)= 0. In order that this problem have a non-trivial solution, we must have X(0)= 0. Also U(L, t)= X(L)T(t)= 0 gives X(L)= 0.
To solve X''(0)= \lambda with boundary conditions X(0)= 0, X(L)= 0, consider possible values for \lambda
1) If \lambda= 0, we have X''= 0 which has general solution X(x)= Ax+ B. Then X(0)= B= 0 and X(L)= AL+ 0= 0 so A= 0. X must be identically 0 which means U must be identically 0 which means we cannot match the initial conditions.
2) If \lambda> 0, we can write \lambda= \alpha^2 with \alpha\ne 0. Now the equation is X''= \alpha^2X which has general solution
X(x)= Ce^{\alpha x}+ De^{-\alpha x}
X(0)= C+ D= 0
X(L)= Ce^{\alpha L}+ De^{-\alpha L}= 0
From the first equation, D= -C so the second equation becomes
Ce^{\alpha L}- Ce^{-\alpha L}= C(e^{\alpha L}- e^{-\alpha L})= 0
But one of those exponentials is greater than 1 while the other is less than 1. The difference cannot be 0 which means we must have C= 0 and then D= 0. Again, that is the trivial solution which we cannot use.
If \lambda< 0, we can write \lambda= -\alphaa^2 with \alpha\ne 0. Now the differential equation for X is X''= -\alpha^2X which has general solution
X(x)= C cos(\alpha x)+ D sin(\alpha x)
X(0)= C= 0
X(L)= D sin(\alpha L)
The only way to avoid D= 0 and another trivial solution is to have sin(\alpha L)= 0 which means \alpha L must be a multiple of \pi: \alpha L= k\pi so \alpha= k\pi/L for integer k.
But then
X(x)= C sin((k\pi/L)x)
satisfies the differential equation
X''= -(k\pi/L)^2X
and the boundary condition X(0)= 0, X(L)= 0 for any C or integer k.
Now that we know \lambda= -\alpha^2= -(k\pi/L)^2 we can write the differential equation of T as
T''(t)= -(k\pi/L)^2T(t)
which also has general solution
T(t)= Acos((k\pi/L)t)+ B sin((k\pi/L)t)
Now, one of the intial conditions is U_t(x, 0)= X(x)T'(0)= 0 which means that we must have
T'(0)= -A(k\pi/L)sin((k\pi/L)0)+ B(k\pi/L)cos((k\pi/L)0)= B(k\pi/L)= 0
so B= 0.
But the other intial condition, U(x, 0)= f(x) cannot be separated in that way.
What we have so far is
U(x,t)= X(x)T(t)= AC sin((k\pi/L)x)cos((k\pi/L)t)
and so
U(x, 0)= C' sin((k\pi/L)x)= f(x)
where I have written C' for AC.
Now for some functions, f(x), that can easily be done- if f(x)= 4sin((3\pi/P)x) it is easy to see that we can set C'= 4 and k= 3 to get
U(x, t)= 4sin((3\pi/L)x)cos((3\pi/L)t)
But what if f(x) were some more complicated function? Say, f(x)= x(L- x) (chosen so that f(0)= 0, f(L)= 0)? Because, as I showed above, sums of solutions to the equation also satisfy the equation, what we can do in that case is combine the solutions for all integer values of k:
U(x, t)= \sum_{k=0}^\infty C_ksin((k\pi/L)x)cos((k\pi/L)t)
and try to find C_k such that
U(x, 0)= \sum_{k=0}^\infty C_k sin((k\pi/L)x)= x(L- x)
That is precisely the "Fourier series" solution.