Quantum mechanics of a single particle
Quantum mechanics can be formulated in many ways. Let's review 2.
1. The Schrodinger picture
Position $x$ and momentum $p$ are time-independent operators, and the wavefunction $\psi(x, t)$ is a complex valued function of the particle's position and of time. The dynamics is defined via the Schrodinger equation
\begin{equation}
i\hbar \frac{\partial \psi}{\partial t} = H(x, p=-i\hbar \nabla) \psi
\end{equation}.
2. The Heisenberg picture
Position $x(t)$ and momentum $p(t)$ are time dependent operators, and the state is time independent (you can think of the state as defining the initial conditions). The dynamics are described by Heisenberg's equations
\begin{eqnarray}
\frac{dx}{dt} &=& \frac{i}{\hbar} [H, x] \\
\frac{dp}{dt} &=& \frac{i}{\hbar} [H, p]
\end{eqnarray}
This mimics Hamilton's equations from classical mechanics when written in terms of the Poisson bracket (here I'll use the subscript ${\rm cl}$ to denote that in this equation $x_{\rm cl}$ and $p_{\rm cl}$ are classical functions, not operators)
\begin{eqnarray}
\frac{dx_{\rm cl}}{dt} &=& \{H_{\rm cl}, x_{\rm cl}\} \\
\frac{dp_{\rm cl}}{dt} &=& \{H_{\rm cl}, p_{\rm cl}\}
\end{eqnarray}
Quantum field theory
Our goal is now to describe relativistic quantum mechanics. Let's first explain an incorrect approach, then describe two correct ways to do it.
0. An incorrect approach
The Schrodinger equation looks non-relativistic; it has one time derivative on the left hand side, and two spatial derivatives on the right hand side. So let's guess that the right way to describe a relativistic quantum particle is to generalize the Schrodinger equation. This was the original idea that led to the Klein-Gordon equation (describing a free particle)
\begin{equation}
-\frac{1}{c^2} \frac{\partial^2 \psi}{\partial t^2} + \nabla^2 \psi = 0
\end{equation}
It turns out that this equation is relevant for relativistic quantum field theory, however this equation is not a generalization of the Schrodinger equation. This is the main point that the textbook authors want you to realize.
In fact, the entire notion of creating relativistic quantum mechanics is doomed from the start, because a relativistic quantum theory is necessarily one where the particle number can change. Tong's lecture notes, for example, give a physical argument for this; due to the uncertainty principle, if you localize a particle well enough it will have relativistic momentum and there is enough energy to transition to states where particle-anti-particle pairs are created.
1. The Schrodinger picture
The Schrodinger picture is rarely used in quantum field theory, but it can be formulated.
The wavefunction becomes a wavefunctional. It is still a function of all the relevant degrees of freedom of the system. However, instead of the degrees of freedom being the position of a single particle, the degrees of freedom are the values of a field $\Phi(x)$ at every location $x$. Therefore, the wavefunctional is a complicated object, $\psi[\Phi(x), t]$, which assigns a single probability amplitude for every possible field configuration $\Phi(x)$. (This usually takes students some thinking before they fully get it).
With this properly generalized and much more complicated wavefunctional, the Schrodinger equation actually looks essentially the same:
\begin{equation}
i \hbar \frac{\partial \psi}{\partial t} = H \psi
\end{equation}
except now the Hamiltonian is a functional of the field operator $\Phi(x)$ and its conjugate momentum $\pi(x)$.
2. The Heisenberg picture
This approach is much more common, and we will finally see the Klein-Gordon equation appearing in the correct place.
The field operators obey the Heisenberg equations of motion
\begin{eqnarray}
\frac{\partial \Phi(x,t)}{\partial t} &=& [H, \Phi] \\
\frac{\partial \pi(x,t)}{\partial t} &=& [H, \pi]
\end{eqnarray}
For the case of a free field, the Hamiltonian is
\begin{equation}
H = \int d^3 x \frac{1}{c^2} \frac{1}{2} \pi^2(x) + \frac{1}{2} (\nabla \Phi)^2
\end{equation}
You can work out all these commutators and you will find that $\Phi$ obeys the Klein-Gordon equation
\begin{equation}
-\frac{1}{c^2} \frac{\partial^2\Phi}{\partial t^2} + \nabla^2 \Phi = 0
\end{equation}
Here we see that the same equation appears that we might have guessed by generalizing the one particle Schrodinger equation. But the correct interpretation is not that $\Phi$ is a wavefunction of a particle. The interpretation of this equation is that it describes the evolution of the operator $\Phi(x, t)$; it is properly understood as a generalization of the Heisenberg equation, not the Schrodinger equation. It is analogous to the corresponding equation of a classical field, much like how Heisenberg's equations in quantum mechanics are analogous to the classical Hamiltonian equations for a single particle.
Best Answer
Let $\mathfrak h $ be the $1$-particle Hilbert space. Let $\mathcal O$ be an operator on $\mathfrak h$. The second-quantized version of this operator acts on an $k$-particle state $S_\nu(\phi_1\otimes\ldots\otimes \phi_k)$ (where $S_{\nu}$ is the (anti-) symmetrization appropriate for the particles at hand) as : $$\hat{\mathcal O}S_\nu(\phi_1\otimes\ldots\otimes \phi_k) = \sum_{i=1}^k S_\nu (\phi_1\otimes\ldots\otimes (O\phi_i)\otimes\ldots\otimes \phi_k)$$
If $\{|\alpha\rangle\}$ are a basis of $\mathfrak h$, we have : $$\hat{\mathcal O} = \sum_{\alpha,\beta} \hat a^\dagger_\beta \langle \beta|\mathcal O|\alpha\rangle \hat a_\alpha$$
To see what happens with internal degrees of freedom, let $\mathfrak h = L^2(\mathbb R^d)\otimes \mathfrak h_{\rm{int}}$ and take $\{\psi_n\}$ be a basis of $L^2(\mathbb R^d)$ and $\{\chi_\sigma\}$ a basis of $\mathfrak h_{\rm{int}}$. With the previous notations, we have $\alpha= (n,\sigma)$ and $|n,\sigma \rangle = \psi_n\otimes \chi_\sigma$.
A scalar operator $\mathcal O$ is one which acts only on the $L^2(\mathbb R^d)$ factor, ie : $$\langle n,\sigma |\mathcal O|m,\sigma'\rangle = \langle n|\mathcal O|m\rangle \delta_{\sigma,\sigma'} = \delta_{\sigma,\sigma'}\int \text d r \psi_n^*(r)\mathcal O\psi_m(r)$$ For such an operator, the second-quantized version reads : \begin{align} \hat {\mathcal O}&=\sum_{n,m,\sigma} \hat a_{n,\sigma}^\dagger\langle n|\mathcal O|m\rangle \hat a_{m,\sigma}\\ &= \sum_{\sigma}\int \text dr \hat\psi^\dagger_\sigma(r) \mathcal O\hat \psi_\sigma(r) \end{align} where we used $\hat \psi_\sigma(r) = \sum_n \hat a_{n,\sigma} \psi_n(r)$. This matches the result in OP. This derivation can also be generalized to operators acting on the spin degrees of freedom.