While one can prove this using the oft-quoted result that if $G/Z(G)$ is cyclic then $G$ is abelian, this fact is not necessary to prove the result.
Assume, for the sake of contradiction, that the order of $Z(G)$ is exactly $p^2$. Since $G\neq Z(G)$, let $x\in G$ be an element with $x\notin Z(G)$.
Then $\langle Z(G),x\rangle$ is strictly larger than $Z(G)$, and hence must have order $p^3$ (since it divides $p^3$ but is strictly larger than $p^2$). Therefore, $\langle Z(G),x\rangle = G$.
But now let $a,b\in Z(G)\cup\{x\}$ be two generators. If at least one of them lies in $Z(G)$, then $ab=ba$. And if this is not the case, then they are both equal to $x$, so again $ab=xx=ba$. Thus, any two elements in the generating set commute, and that implies that $G$ is abelian.
But that yields that $Z(G)=G$ is of order $p^3$, a contradiction. Thus, the order cannot be exacty $p^2$.