How many square roots can a non-identity element in a group have? Let $G$ be a finite group. Let $r_2\colon G \to \mathbb{N}$ be the square-root counting function, assigning to each $g\in G$ the number of $x\in G$ with $x^2=g$. Perhaps surprisingly, $r_2$ does not necessarily attain its maximum at the identity for general groups, see Square roots of elements in a finite group and representation theory.
I'm interested in whether $r_2(g)$ can attain a value above $0.999|G|$ for some non-identity element $g\in G$.
Update: Thanks to everybody who participated in the discussion. The lemma proved here influenced greatly the statement of Theorem 4.2 in https://arxiv.org/pdf/2204.09666.pdf . Proposition 3.12 in this same paper is essentially the answer posted by GH from MO.
 A: Here is an elementary way to prove that there can´t be a finite group $G$ and non-identity $g\in G$ with $r_2(g)>\frac{5}{6}|G|$. Suppose that happens and call $S=\{x\in G; x^2=g\}$. Then of course there must be $x\in G$ with $x,x^{-1}\in S$, so $g^2=1$.
Now for every $x\in G$, $S\cap x^{-1}S$ has more than $\frac{2|G|}{3}$ elements. If for each $y\in G$ you consider the set $A_y=\{x\in G;y\in S\cap x^{-1}S\}$, then $\sum_{y\in G}|A_y|=\sum_{x\in G}|S\cap x^{-1}S|>|G|\frac{2|G|}{3}$, so there is some $y$ with $|A_y|>\frac{2|G|}{3}$. So, $|S\cap A_y|>\frac{|G|}{2}$. Pick $x\in S\cap A_y$.
Then we have $y^2=xyxy=x^2=g$.
From these equalities we deduce $xyx=y$, and as $x^2y^2=g^2=1$, we have $xy=x^{-1}y^{-1}$. So, $y=xyx=x^{-1}y^{-1}x$. This means that for all possible choices of $x$, which is more than $\frac{|G|}{2}$, $x^{-1}y^{-1}x= y$. So, $x^{-1}y^{-1}x=y$ for all $x$, which is impossible since $y\neq y^{-1}$.
Edit: As Emil Jeřábek points out in the comments, this argument can be refined to prove that $r_2(g)>\frac{3}{4}|G|$ can´t be achieved. The bound $r_2(g)=\frac{3}{4}|G|$ is reached in the example Derek Holt mentions in his answer: the group $Q_8$ and its element $g$ with $r_2(g)=6$.
A: I am just turning my comment into an answer. The answer to the question is no. I think the highest possible value of $r_2(g)$ with $g \ne 1$ is $r_2(g) = 3/4$ for the central element $g$ of $Q_8$, but I haven't proved that formally.
In general, suppose that $g \ne 1$ and $r_2(g) > |G|/2$. Then  since conjugate elements of $G$ have the same value of $r_2$, we must have $g \in Z(G)$.
We also have $g^2=1$, since otherwise we would have $r_2(g) = r_2(g^{-1})$.
So the proportion of elements of $G/\langle g \rangle$ with $g^2 = 1$ is at least $r_2(G)$. Now, it is proved here that if at least $3/4$ of the elements of finite group $H$ satisfy $g^2=1$ then $H$ is an elementary abelian $2$-group, so  this applies to $G/\langle g \rangle$.
Now $G$ is a central product of $Z := Z(G)$ with the inverse image $E$ in $G$ of a complement $E/\langle g \rangle$ of $Z/\langle g \rangle$ in $G/\langle g \rangle$. Then clearly $Z(E) = [E,E] = \langle g \rangle$, so $E$ is an extraspecial $2$-group. Note also that $Z$ is either elementary abelian or it is the direct product of an elementary abelian group with $C_4$.
Now the elements of order $2$ and $4$ in extraspecial groups correspond to the number of elements with $Q(x)=0$ or $1$ in a quadratic form over ${\mathbb F}_2$. We get the highest number of order $4$ in extraspecial groups of minus-type, where the proportion, for a group of order $2^{1+2k}$, is $1/2 + 1/2^{k+3}$, which gives a maximum of $3/4$ when $k=1$.
It seems clear that taking the central product with $Z$ will not change this proportion significantly - in fact it seems to reduce it for the minus-type group.
A: Here is a streamlined and simplified version of the posts by Saúl Rodríguez Martín and Emil Jeřábek.
Theorem. Assume that $G$ is a finite group, and $r_2(g)>(3/4)|G|$ holds for some $g\in G$. Then $G$ is an elementary abelian $2$-group, and $g$ is the identity element.
Proof. Fix any element $y\in G$, and consider the sets
$$S=\{x\in G: x^2=g\},\qquad T=\{x\in S:xy\in S\}.$$
By the union bound,
$$|G\setminus T|\,\leq\, 2|G\setminus S|<|G|/2,$$
hence $|T|>|G|/2$. For any $x\in T$, we have $(xy)^2=x^2$,
which implies that
$$xyx^{-1}=(xy)x^{-1}=(xy)^{-1}x=y^{-1}.$$
So $\{x\in G:xyx^{-1}=y^{-1}\}$ contains more than half of the elements of $G$, whence it contains all elements of $G$. In particular, $y=y^{-1}$, which shows that $G$ is an elementary abelian $2$-group. Moreover, $g$ is the identity element, since the identity element is the only square in $G$.
A: In principle one can get an exact answer to this question by a lot of case checking and a quantitative version of the following result.

Theorem.  Let $G$ be a finite group such that $r_2(g) \geq \varepsilon |G|$ for some $g \in G$ and $\varepsilon > 0$.  Then $G$ contains a subgroup $H$ of index $O_\varepsilon(1)$ which is $2$-step nilpotent with $|[H,H]| \ll_\varepsilon 1$.

Roughly speaking, this says that a group $G$ with a large value of $r_2$ must be ``bounded-by-abelian-by-bounded'', which should be enough structure to then do a case analysis, at least in principle.
Proof.  Since all conjugates of $g$ have a value of $r_2$ greater than or equal to $\varepsilon |G|$, there are at most $1/\varepsilon$ conjugates of $g$.  Thus the centraliser $C_G(g)$ of $g$ has index $O_\varepsilon(1)$ (cf., Derek Holt's comment).  By the pigeonhole principle, there is a coset $x C_G(g)$ of $C_G(g)$ which contains $\gg_\varepsilon |G|$ solutions $xt, t \in C_G(g)$ to the equation $(xt)^2 = g$; by shifting $x$ without loss of generality we may also assume that $x^2=g$.  From $x^2 = g$ we have $x = x^{-1} g$ and hence $(xt)^2 = xtx^{-1} gt = xtx^{-1} tg$ since $t \in C_G(g)$.  Thus the equation $(xt)^2=g$ is equivalent to
$$xtx^{-1} = t^{-1}.\quad (1)$$
So (1) holds for $\gg_\varepsilon |G|$ choices of $t \in G$.  In particular, for $\gg_\varepsilon |G|^2$ pairs $(t,s) \in G^2$, we have
$$ xtx^{-1} = t^{-1}; \quad xts x^{-1} = s^{-1} t^{-1}$$
which implies
$$ xsx^{-1} = t s^{-1} t^{-1}.$$
By Cauchy-Schwarz, this implies that there are $\gg_\varepsilon |G|^3$ triples $(s,t_1, t_2)$ such that
$$ t_1 s^{-1} t_1^{-1} = t_2 s^{-1} t_2^{-1}$$
and so there are $\gg_\varepsilon |G|^2$ solutions to the equation $xyx^{-1} = y$.  In other words, the commuting probability of $|G|$ is $\gg_\varepsilon 1$. The claim then follows from a theorem of Neumann (see Theorem 2.4 of this paper of Eberhard). $\Box$
I suspect that in the case $\varepsilon > 1/2$ one can work a little harder and show that one can assume without loss of generality that the abelianisation $H/[H,H]$ is $2$-torsion, so that $G$ is ``virtually'' a $2$-torsion group in some weak sense.  On the other hand, once $\varepsilon$ reaches $1/2$ one can have non-$2$-torsion behavior.  For instance, let $H$ be an arbitrary abelian group, let $g$ be an arbitrary element of $H$ [EDIT: as pointed out by Will below, one needs to assume that $g$ is of order $2$], and consider the group $\langle H, e \rangle$ where $e$ is subject to the relations $e^2 = g$, $ehe^{-1} = h^{-1}$ for all $h \in H$ (this is a sort of twisted dihedral group, I don't know the official name for it).  Then $G = \langle H,e \rangle$ is a group containing $H$ as an index $2$ subgroup with $r_2(g) = |G|/2$.
