As stated here, for $f =
f(t, x) ∈ C^{1,2}(\mathbb{R}^2)$ a deterministic function and Ito process $$X_t = W_t^2,$$ the stochastic process
$$Y_t = f(t,X_t)$$
is an Ito process and we have
$$df (t,X_t) = \partial_tf(t,X_t)\,dt + \partial_xf(t,X_t)\,dX_t +
\frac{1}{2} \partial_{xx}^2f(t,X_t)(dX_t)^2. $$
Since
$$ dX_t = 2W_t dW_t + dt $$ and
$$ (dX_t)^2 = 4X_t dt, $$
we have
$$ df (t,X_t) = \left(\partial_tf(t,X_t) + 2X_t \partial_{xx}^2f(t,X_t) +\partial_xf(t,X_t) \right)\,dt
+2\partial_xf(t,X_t)W_t dW_t $$
So, to make $f(t,X_t) = f(t,W_t^2)$ martingale, all we need is deterministic functions $f=f(t,x)$ such that
$$ \partial_tf(t,x) + 2x\partial_{xx}^2f(t,x) +\partial_xf(t,x) = 0,$$
for all $t$ and $x$, which reduce the SDE to:
$$ df (t,X_t) = 2\partial_xf(t,X_t)W_t dW_t $$
Note: In your example:
$$f(t,x)= x- t$$
and $(\partial_xf)(t,x) = 1$, so $(\partial_xf)(t,X_t) = (\partial_xf)(t,W_t^2) = 1$
Note 2: Another example (to bring in a non-zero second derivative in $x$) is:
$$ f(t,x) = x^2-6xt +3t^2 $$
Here, $(\partial_xf)(t,x) = 2x-6t$, so $(\partial_xf)(t,X_t) = (\partial_xf)(t,W_t^2) = 2W_t^2 -6t$.
(Example inspired by Hermite polynomials - fourth one, $H_4(t,x) = x^4-6x^2t+3t^2$ - which we know produce martingales.)