I'm going to begin with a prelude about constructing the solution using the action/Lagrangian formalism in order to provide context and a point of comparison for the canonical one. The main question will begin at the horizontal line.
The inhomogeneous Klein-Gordon equation can be derived by minimizing the action \begin{align} S\left[\phi\right] &= \int \operatorname{d}^4x \mathcal{L}(\phi,\partial_0\phi) \\ & = \int \operatorname{d}^4 x \left[\frac{1}{2}\partial_\mu\phi\partial^\mu\phi - \frac{m^2}{2}\phi^2 + J\phi\right] \end{align} with $\operatorname{sig}(\eta_{\mu\nu}) = (+,-,-,-)$. Finding the stationary point in the action with respect to the field $\phi(t,\mathbf{x})$ produces the inhomogeneous Klein-Gordon equation \begin{align} \frac{\delta S[\phi]}{\delta \phi(t,\mathbf{x})} & = 0 \\ & = - \ddot{\phi} + \nabla^2\phi - m^2\phi + J. \end{align} If we define the retarded Green's function as \begin{align} \left[\frac{\partial^2}{\partial t^2} - \nabla^2 + m^2\right] G_{\mathrm{ret}}(t,\mathbf{x};t',\mathbf{x}') & = \delta(t-t')\,\delta(\mathbf{x}-\mathbf{x}') \\ G_{\mathrm{ret}}(t,\mathbf{x};t',\mathbf{x}') & = 0\ \forall\, t \le t' \Rightarrow \\ \left.\partial_t G_{\mathrm{ret}}(t,\mathbf{x};t',\mathbf{x}')\right|_{t=t'} & = \delta(\mathbf{x}-\mathbf{x}'), \end{align} then if we multiply the equation of motion by $G_{\mathrm{ret}}(t,\mathbf{x};t',\mathbf{x}')$, integrate over all of space-time, and integrate by parts to move the derivatives over to the Green's function yields \begin{align} \phi(t \ge 0,\mathbf{x}) &= \int \operatorname{d}^4x\, G_{\mathrm{ret}}(t,\mathbf{x};t',\mathbf{x}')\, J(t',\mathbf{x}') \\ &\hphantom{=} + \int \operatorname{d}^3x \left[\frac{\partial G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')}{\partial t} \phi(0,\mathbf{x}') + G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')\, \dot{\phi}(0,\mathbf{x}')\right], \end{align} if we assume the fields at spatial infinity vanish. Note that we don't have to worry about the value of the field and its derivative at $t'=t_{\mathrm{final}}$ because of our use of the retarded Green's function. To reconstruct $\phi(t\le 0,\mathbf{x})$, simply substitute the advanced propagator for the retarted one.
The canonical approach begins with defining the canonically conjugate momentum \begin{align} \pi(t,\mathbf{x}) & \equiv \frac{\partial \mathcal{L}}{\partial \partial_0 \phi} \\ & = \frac{\partial \phi}{\partial t} \end{align} and from there defining the Hamiltonian \begin{align} H & \equiv \int \operatorname{d}^3x \left[\pi \partial_0 \phi - \mathcal{L}\right] \\ & = \int\operatorname{d}^3x\left[ \frac{1}{2}\pi^2 + \frac{1}{2} (\nabla\phi)^2 + \frac{m^2}{2}\phi^2, \right] \end{align} where I've dropped the $J$ term because it's no longer relevant.
The canonical equations of motion then become \begin{align} \dot{\phi}(t,\mathbf{x}) & = \frac{\delta H}{\delta \pi(\mathbf{x})} \\ & = \pi(t,\mathbf{x}) \\ \dot{\pi}(t,\mathbf{x}) & = -\frac{\delta H}{\delta \phi(\mathbf{x})} \\ & = \nabla^2\phi(t,\mathbf{x}) - m^2\phi(t,\mathbf{x}) \end{align} where the phase space is now defined by $(\phi,\pi)$. It's clear that the canonical equations of motion can be combined to show that both $\phi$ and $\pi$ obey the Klein-Gordon equation. We can use that fact to reproduce the behavior of $\phi$ as $$ \phi(t,\mathbf{x}) = \int \operatorname{d}^3x \left[\frac{\partial G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')}{\partial t} \phi(0,\mathbf{x}') + G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')\, \pi(0,\mathbf{x}')\right].$$
The question comes from asking how we define the time evolution of $\pi(t,\mathbf{x})$? If we apply the first canonical equation of motion we get \begin{align} \pi(t,\mathbf{x}) &= \int \operatorname{d}^3x \left[\frac{\partial^2 G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')}{\partial t^2} \phi(0,\mathbf{x}') + \frac{\partial G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')}{\partial t} \pi(0,\mathbf{x}')\right] \end{align} using the defining equation for the Green's function this becomes \begin{align} \pi(t,\mathbf{x}) &= \int \operatorname{d}^3x \left[ \left(\nabla^2 G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}') - m^2 G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}') + \delta(t)\,\delta(\mathbf{x}-\mathbf{x}') \right) \phi(0,\mathbf{x}') \right. \\ & \hphantom{=\int \operatorname{d}^3x}\ \ \left.+ \frac{\partial G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')}{\partial t} \pi(0,\mathbf{x}')\right]. \end{align} Now, the boundary conditions on $G_{\mathrm{ret}}$ make it so that the boundary condition for $\phi$, $\phi(t=0,\mathbf{x}) =\phi(0,\mathbf{x})$ is satisfied. The boundary condition for $\pi$ appears to be violated, though. Plugging in $t=0$ to the equation for $\pi$ gives \begin{align} \pi(t=0,\mathbf{x}) & = \pi(0,\mathbf{x}) + \delta(0)\,\phi(0,\mathbf{x}), \end{align} which violates the initial boundary condition.
We can guarantee the initial boundary condition is satisfied if we mimic the construction we used for $\phi$ to get \begin{align} \pi(t,\mathbf{x}) &= \int \operatorname{d}^3x \left[G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}') \dot{\pi}(0,\mathbf{x}') + \frac{\partial G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')}{\partial t} \pi(0,\mathbf{x}')\right] \\ & = \int\operatorname{d}^3x \left[G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}') (\nabla'^2-m^2)\phi(0,\mathbf{x}') + \frac{\partial G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')}{\partial t} \pi(0,\mathbf{x}')\right]\ \mathrm{by\ 2^{nd}\ canon\ E.O.M.} \\ & = \int\operatorname{d}^3x \left[\left((\nabla^2-m^2)G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')\right) \phi(0,\mathbf{x}') + \frac{\partial G_{\mathrm{ret}}(t,\mathbf{x};0,\mathbf{x}')}{\partial t} \pi(0,\mathbf{x}')\right], \end{align} which obviously satisfies $\pi(t=0,\mathbf{x}) = \pi(0,\mathbf{x})$, but violates the equation of motion $\pi = \dot{\phi}$ at $t=0$.
Is this apparent contradiction a problem? If it is a problem, what is the correct way to get around it (e.g. which version of $\pi(t,\mathbf{x})$ is correct and why)? If it's not, why not?