As Ralph is being modest, I have decided to make his comment into a CW answer.
Recall that the short exact coefficient sequence $0\to \mathbb{Z}\to \mathbb{Z}\to \mathbb{Z}/2\to 0$ leads to a long exact sequence
$$
\cdots \to H^\ast(X;\mathbb{Z})\to H^\ast(X;\mathbb{Z})\stackrel{\rho}{\to} H^\ast(X;\mathbb{Z}/2)\stackrel{\beta}{\to} H^{\ast+1}(X;\mathbb{Z})\to\cdots $$
for any space $X$, where $\rho$ denotes reduction mod 2 and $\beta$ is the Bockstein homomorphism. Recall also that $\rho$ is a ring homomorphism, and that $\rho\circ\beta = Sq^1$, the first Steenrod square.
Let $X=\mathbb{R}P^\infty\times\mathbb{R}P^\infty$, and let $x,y\in H^1(X;\mathbb{Z}/2)$ denote the generators over each axis. Note that $c=\beta(xy) \in H^3(X;\mathbb{Z})$ is nonzero, since $$\rho(c) = Sq^1(xy) = Sq^1(x)y + x Sq^1(y) = x^2y + xy^2 \neq 0.$$
Similarly $c^2 \in H^6(X;\mathbb{Z})$ is nonzero, since we have
$$ \rho(c^2) = \rho(c)^2 = (x^2y+xy^2)^2 = x^4y^2 + x^2 y^4 \neq 0.
$$
As Will Sawin noted in his comment, we can get a finite-dimensional example by taking $Y=X^{(6)}$, the $6$-skeleton of $X$ (this is the smallest possible dimension, by Tom Goodwillie's comment). We could also take $Y=\mathbb{R}P^4\times\mathbb{R}P^4$ (but $ \mathbb{R}P^3\times\mathbb{R}P^3$ won't work, since its six-dimensional cohomology is torsion-free).