Differentiating the sum and plugging it into our wave equation yields \[\sum_{n\in\mathbb{Z}}a_n^{\prime\prime}(t)e^{inx}=c^2\sum_{n\in\mathbb{Z}}a_n(t)\left( in\right)^2e^{inx}.\] The uniqueness of the Fourier coefficients implies that \(a_n(t)\) must solve the equation \[a_n^{\prime\prime}(t) = -n^2c^2 a_n(t),\] which is the desired result.
The solution to the above sequence of ODEs is given by \[a_0(t)=A_0+B_0t,\] and \[a_n(t) = A_n\cos\left( nct\right)+B_n\sin\left( nct\right)\] when \(n\not=0\). At this point we will need to use our boundary condition for \(u\left( x,0\right)\) and \(u_t\left( x,0\right)\). Since \[u_t\left( x,t\right) = \sum_{n\in\mathbb{Z}}a_n^{\prime}(t)e^{inx}\] we conclude that \(u_t\left( x,0\right)=0\) implies, together with the uniqueness of the Fourier coefficients, that \[a_n^{\prime}(0)=0,\qquad \forall n\in\mathbb{Z}.\] As \[a_0^{\prime}(t)=B_0\] and \[a_n^\prime(t) = -ncA_n\sin\left( nct\right)+ncB_n\cos\left( nct\right),\] when \(n\not=0\) we find that \(B_n=0\) for all \(n\in\mathbb{Z}\). Thus, we have that \[a_n(t)=A_n \cos\left( nct\right),\qquad n\in\mathbb{Z}.\] Using the fact that \(u(x,0)=f(x)\) we find that \[\sum_{n\in\mathbb{Z}}a_n(0)e^{inx}=u\left( x,0\right)= f(x)= \sum_{n\in\mathbb{Z}}\widehat{f}_ne^{inx}\] and, like before, the uniqueness of the Fourier coefficients imply that \[A_n=a_n(0)=\widehat{f}_n,\qquad \forall n\in\mathbb{Z}.\]
Combining the previous results we conclude that our solution is given by \[u(x,t) = \sum_{n\in\mathbb{Z}}\widehat{f}_n \cos\left( nct\right)e^{inx}\]