Fibered surface is flat if and only if it surjects onto the base At the beginning of section 8.3.1 of Liu's "Algebraic geometry and arithmetic curves", he defines a fibered surface $\pi\colon  X \to S$ (I am only interested in the case when the base scheme is $S=\mathrm{Spec}\mathbb{Z}$) and immediately remarks that flatness and surjectivity of $\pi$ are equivalent. Why is that so? And does he mean surjectivity onto the underlying space or as a morphism of sheaves or both?
 A: This answer assumes the hypothesis of the definition in Liu mentioned in the question.
$\textbf{Let $\pi$ be surjective}$.
There is a local homomorphism of local rings $\pi^* : \mathcal{O}_{f(x),S} \rightarrow \mathcal{O}_{x,X}$ induced by $\pi$.
$\textit{Claim}$ : $\pi$ is flat.
We know that $S$ is integral. Hence there is an inclusion of function fields that is $$k(S) \hookrightarrow k(X)$$ This in particular implies that the map $\pi^*$ induce on rings is an inclusion for all $x \in X$ as the local rings of both the schemes are subrings of the local ring at the generic point of respective schemes($X$ and $S$ are integral schemes).
Recall that for module over DVR's flatness is equivalent to the module being torsion free.
Since $\mathcal{O}_{x,X}$ is of course torsion free on account of being an integral domain, we get that the map $\pi$ is flat.
Now for the other part. $\textbf{Assume $\pi$ is flat}$.
Then the image of $\pi$ is open since $\pi$ is flat. Also the book assumes $\pi$ to be a projective morphism and hence proper and thus has closed image. Thus Image($\pi$)(is non-empty) is both open and closed and since $S$ is irreducible in particular connected, this implies that $\pi$ is surjective.
