Mutating a List
is generally a difficult and inefficient way to get things done in Mathematica. I think it's much easier to define a function that yields rewritten list elements as needed, and use the magic Nothing
to excise unwanted results.
First the case we want:
f[x_Integer] := x^2
Now, a catch-all for the cases we don't want:
f[_] := Nothing
Then, just Map
f
to your input:
Map[f, {1, 2, 3, Pi, E, 5}]
(*
{1, 4, 9, 25}
*)