If as usual we set
$z = x + iy \tag{1}$
and
$f(z) = u(x, y) + iv(x, y), \tag{2}$
then the condition
$(\operatorname{Re}(f(z)))^2 = \operatorname{Im}(f(z)) \tag{3}$
may be written
$v = u^2;\tag{4}$
thus $f(z)$ becomes
$f(z) = u(x, y) + iu^2(x, y). \tag{5}$
Since $f(z)$ is holomorphic, $u(x, y)$ and $v(x, y) = u^2(x, y)$ are harmonic; that is,
$\nabla^2u = 0 \tag{6}$
and
$\nabla^2 u^2 = 0. \tag{7}$
We compute $\nabla^2u^2$; we have
$\nabla^2 u^2 = \nabla \cdot \nabla u^2$
$= \nabla \cdot (2u \nabla u) = 2\nabla u \cdot \nabla u + 2u \nabla^2u$
$= 2 \vert \nabla u \vert^2, \tag{8}$
using (6); in deriving (8), we have also used the standard identity
$\nabla \cdot (gX) = \nabla g \cdot X + g \nabla \cdot X, \tag{9}$
holding for differeniable scalar functions $g$ and vector fields $X$; for more, see https://en.m.wikipedia.org/wiki/Vector_calculus_identities. It follows from (7) and (8) that
$\vert \nabla u \vert^2 = 0, \tag{10}$
or
$\vert \nabla u \vert = 0, \tag{11}$
or
$\nabla u = 0; \tag{12}$
we conclude that $u(x, y)$ must be a real constant $c$; it follows then that $v(x, y) = c^2$ and, finally $f(z)$ is a complex constant of the form
$f(z) = c + ic^2, \tag{13}$
where $c \in \Bbb R$.
Nota Bene: The technique used above, viz. showing that $\nabla u = 0$, may be applied to other, similar questions as well; see for example the
Related Problem:
Can we conclude that $u^{-1}+iu$ is constant?