The question Let $G$ be a group of order $8$ and $x$ be an element of $G$ of order $4$. Prove that $x^2 \in Z(G)$ already posted here. But the answer is not given there. SO I have tried to solve the problem.
Let us consider the subgroup $H=\langle x\rangle=\{e,x,x^2,x^3\}$. Then $[G:H]=2$. The cosets of $H$ in $G$ are $H$ and $g-H$. The quotient group is of order $2$. Therefore $(G-H)^2=H, H$ being the identity element in the quotient group.
Let $x\in H$. Then $x^2\in H$. If $x\in G-H$. Then $(xH)^2=(G-H)^2=H\implies x^2H=H\implies x^2\in H$. Therefore for every $x\in G, x^2\in H$. If I can show that $H=Z(G)$, then everything is done. Is it possible to show this ?