Fourier Transforming the Klein Gordon Equation Starting with the Klein Gordon in position space,
\begin{align*}
\left(\frac{\partial^2}{\partial t^2} - \nabla^2+m^2\right)\phi(\mathbf{x},t) = 0
\end{align*}
And using the Fourier Transform: $\displaystyle\phi(\mathbf{x},t) = \int \frac{d^3p}{(2\pi)^3}e^{i \mathbf{p} \cdot\mathbf{x}}\phi(\mathbf{p},t)$:
\begin{align*}
\int \frac{d^3p}{(2\pi)^3}\left(\frac{\partial^2}{\partial t^2} - \nabla^2+m^2\right)e^{i \mathbf{p} \cdot\mathbf{x}}\phi(\mathbf{p},t)&=0 \\
\int \frac{d^3p}{(2\pi)^3}e^{i \mathbf{p} \cdot\mathbf{x}}\left(\frac{\partial^2}{\partial t^2} +|\mathbf{p}|^2+m^2\right)\phi(\mathbf{p},t)&=0
\end{align*}
Now I don't understand why we are able to get rid of the integral, to be left with \begin{align*}
\left(\frac{\partial^2}{\partial t^2} +|\mathbf{p}|^2+m^2\right)\phi(\mathbf{p},t)=0
\end{align*}
 A: You can see $\left(\frac{\partial^2}{\partial t^2} +|\mathbf{p}|^2+m^2\right)\phi(\mathbf{p},t)$ as the Fourier transform of your function. And which is your function? 0, and what is 0-s Fourier transform, well zero.
A: Since $e^{i\textbf{p}\cdot \textbf{x}}$ is a plane wave, it will integrate to infinity when the integral is taken over all of momentum space.  If the integral is to evaluate to zero then the remaining term $\left(\partial_t^2 + |\textbf{p}^2| + m^2\right)\phi\left(\textbf{p}, t\right)$ has to be identically zero.
A: The functions  $e^{i \bf p \cdot \bf x}$ as functions of $\bf x$ are linearly independent for different $\bf p$'s, hence every coefficient in the linear superposition (that is, in the integral) must be zero.
A: The reason you can get rid of the integral and the exponential is due to the uniqueness of the Fourier transform. Explicitly we have,
\begin{align} 
\int \frac{ \,d^3p }{ (2\pi)^3 } e ^{ i {\mathbf{p}} \cdot {\mathbf{x}} } \left( \partial _t ^2 +  {\mathbf{p}} ^2 + m ^2  \right)  \phi ( {\mathbf{p}} , t ) & = 0 \\ 
\int d ^3 x \frac{ \,d^3p }{ (2\pi)^3 } e ^{ i ( {\mathbf{p}} - {\mathbf{p}} ' ) \cdot {\mathbf{x}} } \left( \partial _t ^2 + {\mathbf{p}} ^2 + m ^2  \right)  \phi ( {\mathbf{p}} , t ) & = 0 \\ 
 \left( \partial _t ^2 + {\mathbf{p}} ^{ \prime 2} + m ^2 \right)  \phi ( {\mathbf{p}'} , t ) & = 0
\end{align} 
where we have used,
\begin{equation}
\int d ^3 x e ^{- i ( {\mathbf{p}} - {\mathbf{p}} ' ) \cdot x } = \delta ( {\mathbf{p}} - {\mathbf{p}} ' ) 
\end{equation}
and 
\begin{equation} 
\int \frac{ d ^3 p }{ (2\pi)^3 } \delta ( {\mathbf{p}} - {\mathbf{p}} ' ) f ( {\mathbf{p}} ) = f ( {\mathbf{p}} ' ) 
\end{equation}
