This is just an addition to Andreas Caranti's answer.
I don't know how much you know about semidirect products and exact sequences, but as I like this view on semidirect products the most, we will try it:
A group $G=H\rtimes K$ is the semidirect product of two groups $H$ and $K$ iff there is a exact sequence of groups $$0\rightarrow H\rightarrow G\rightarrow K\rightarrow 0,$$ that splits.
Now we see what happens:
$Z_{p^2}$ is a normal subgroup, so there is an exact sequence
$$0\rightarrow Z_{p^2}\rightarrow G\rightarrow G/(Z_{p^2})\rightarrow 0$$ and as $Z_{p^2}$ has index $p$ in $G$, we get that $G/(Z_{p^2})$ has $p$ elements, so it's just isomorphic to $Z_{p}$.
So what is left? This sequence has to split and it splits iff there is an element of order $p$ in $G\setminus H$. This is exactly, what Andreas Caranti showed.
Edit: Artus asked, what Lemma 4.7.15 has to do with the fact, that the induced homomorphism $\alpha$ is not trivial. I will do this in a more general context.
If $G\cong H\rtimes_{\alpha} K$, then $H$ is a normal subgroup in $G$, $K$ is just a regular subgroup in $G$ and $\alpha(k)$ is just the conjugation with $k$ in $G$ restricted to $H$, which is an element of $Aut(H)$ as $H$ is normal.
So what about your situation? $\alpha$ is then trivial, iff the conjugation with all elements of $K$ restricted to $H$ is trivial, what is the case iff $H$ commutes with $K$ and as $H$ is abelian in your case, $H$ commutes with $H$ too, so $H$ lies in the center of $G$. Lemma 4.7.15 says, that this is not possible, so $\alpha$ is not trivial.
I jused some identifications like $H\cong H\times\{1\}$ and so on...
Assuming $H$ is a non normal subgroup of order $2$.
Consider Action of $G$ on set of left cosets of $H$ by left multiplication.
let $\{g_iH :1\leq i\leq 3\}$ be cosets of $H$ in $G$.
(please convince yourself that there will be three distinct cosets)
we now consider the action $\eta : G\times\{g_iH :1\leq i\leq 3\} \rightarrow \{g_iH :1\leq i\leq 3\}$ by left multiplication.
i.e., take an element $g\in G$ and consider $g.g_iH$ as there are only three distinct sets we get $g.g_iH = g_jH$ for some $j\in \{1,2,3\}$
In this manner, the elements of $g\in G$ takes cosets $g_iH$ (represented by $i$) to cosets $g_jH$ (represented by $j$)
i.e., we have map $\eta :\{1,2,3\} \rightarrow \{1,2,3\}$
which can be seen as $\eta : G\rightarrow S_3$
we know that $Ker(\eta)$ is normal in $G$ which is contained in $H$.
As $H$ is not normal in $G$ we end up with the case that $Ker(\eta)=(1)$ i.e., $\eta$ is injective.
i.e., we have $G$ as a subgroup(isomorphic copy) of $S_3$. But, $|G|=|S_3|=6$. Thus, $G\cong S_3$.
So, for any non abelian group $G$ of order $6$ we have $G\cong S_3$.
For an abelian group of order $6$ we have already know that $G$ is cyclic and $G\cong \mathbb{Z}_6$.
So, only non isomorphic groups of order $6$ are $S_3,\mathbb{Z}_6$.
Best Answer
Suppose $p$ is odd. Consider the kernel of $\phi$ in the second fact. It consists exactly of the elements of order dividing $p$, and so there are either $p^2$ or $p^3$ of these; always more than $p$. However, by the first fact, there are exactly $p$ central elements of order dividing $p$. In particular, for every odd prime $p$ and non-abelian $p$-group $G$, there is a non-central element of order $p$, and the subgroup it generates is not normal (since it is order $p$ and not central by assumption).
Suppose $p=2$. Then there are two very explicit cases, $D_8$ which doesn't work, and $Q_8$ which does.
Groups like this, in which every element of order $p$ are central, have been studied by JG Thompson and others. Maps like $\phi$ always exist, and serve to build the upper exponent-$p$ series of the group. In particular, if $Z(G)$ is cyclic, $p$ is odd, and every element of order $p$ is central, then $G$ itself is cyclic. If $Z(G)$ has rank 2, then the “socle series” of $G$ has factors of rank at most 2.