\phi(0) is not a number, it is an operator at a specified location in spacetime, which in this case is at the origin of it.
It makes sense that it can only depend on k^2 and k^2 = -M^2, which we are summing over. This is acceptable if the interchange of the summation over 'n' and the integral...