For example, consider the following problem $$\frac{\partial u}{\partial t} = k\frac{\partial^2 u}{\partial x^2},\hspace{0.5cm} u(x,0)=f(x),\hspace{0.5cm} u(0,t)=0,\hspace{0.5cm} u(L,t)=0$$ Textbooks (e.g., linkPaul's Online Notes) usually apply separation of variables, assuming that $u(x,t)=\varphi(x)G(t)$ without any explanation why this assumption can be made.
Do we lose any solutions that way given that there are functions of two variables $x$ and $t$ that are not products of functions of individual variables?
Separation of variables gives the following solution when we consider only boundary conditions: $$u_n(x,t) = \sin\left(\frac{n\pi x}{L}\right)e^{-k\left(\frac{n\pi}{L}\right)^2t},\hspace{0.5cm}n=1,2,3,...$$$$u_n(x,t) = \sin\left(\frac{n\pi x}{L}\right)e^{-k\left(\frac{n\pi}{L}\right)^2t},\hspace{0.5cm}n=1,2,3,\dotsc.$$
The equation is linear, so we can take a superposition of $u_n$: $$u(x,t) = \sum\limits_{n=1}^{\infty}B_n\sin\left(\frac{n\pi x}{L}\right)e^{-k\left(\frac{n\pi}{L}\right)^2t}$$ where $B_n$ are found from the initial condition: $$B_n = \frac{2}{L}\int\limits_0^Lf(x)\sin\left(\frac{n\pi x}{L}\right)dx,\hspace{0.5cm}n=1,2,3,...$$$$B_n = \frac{2}{L}\int\limits_0^Lf(x)\sin\left(\frac{n\pi x}{L}\right)dx,\hspace{0.5cm}n=1,2,3,\dotsc.$$
Are there solutions $u(x,t)$ that cannot be represented this way (not for this particular pde but in general)? What happens in the case of non-linear equations? Can we apply separation of variables there?