Ho lambda and for-loop strikes back! My bad!
tldr: it saved the lambda with references to the python variables, So when the lambda is called during the backward (at the y,backward() line) t has the wrong value.
Using this as the function should work:
# Inside the loop
def fn(x, t=t):
    fun(theta, t)

The default argument is saved at the function creation time, so each iteration will have its own version of the default argument based on the current value of t.