I really dislike this way of phrasing this particular problem (or rather, the typical more general statement of which this problem is a special case), precisely because it just leads to confusions because it contradicts (or seems to contradict) the initial hypothesis.
The general statement they are alluding to is:
Let $G$ be a group, and suppose that $N\leq Z(G)$ is such that $G/N$ is cyclic. Then $G$ is abelian.
The proof is: let $g\in G$ be such that $gN$ generates $G/N$, and let $x,y\in G$. Then there exist $a,b\in\mathbb{Z}$ and $n_1,n_2\in N$ such that $x=g^an_1$ and $y=g^bn_2$. Then we have:
$$\begin{align*}
xy &= (g^an_1)(g^bn_2)\\
&= g^ag^bn_1n_2 &&\text{(since }n_1\in N\subseteq Z(G)\text{)}\\
&= g^bg^a n_2n_1 &&\text{(since }n_2\in Z(G)\text{)}\\
&= (g^bn_2)(g^an_1) &&\text{(since }n_2\in Z(G)\text{)}\\
&= yx.
\end{align*}$$
Thus, for all $x,y\in G$, $xy=yx$; hence, $G$ is abelian. $\Box$
Often, this statement is given as:
Let $G$ be a group such that $G/Z(G)$ is cyclic. Then $G$ is abelian.
This is fine, but then it leads to confusion because in fact $G/Z(G)$ will be trivial. Worse is when it is stated as:
Let $G$ be a group such that $G/Z(G)$ is nontrivial and cyclic. Then $G$ is abelian.
This is worse because of course the next step after the conclusion that $G$ is abelian is that $Z(G)=G$, so then $G/Z(G)$ is not, in fact, nontrivial (and cyclic). Thus, you end up proving that the assumption cannot hold.
The problem you have is an even worse special case of this; in fact, what you conclude is not merely that $G$ is abelian, but that the very assumption that led you to that conclusion is impossible. That is, you actually prove that
There does not exist a (finite) group $G$ such that $|G/Z(G)| = p$ where $p$ is a prime.
It’s bad form; it’s bad form because it asks you to prove something that contradicts the hypothesis on which you are proving it. It is bad form because it is part of a proof by contradiction that does not need to be a proof by contradiction (a particular pet peeve of mine). It’s bad form because it leads to confusion by anyone who dares to take a step back after finishing the proof and tries to understand the whole argument and its implications. In short, it is a disservice to good students like yourself who want to look beyond the immediate task at hand.