Awesome, glad I could help!
You have two recurrent parts, the previous prediction as well as the hidden state of the LSTM. Detaching these will stop gradients flowing back in time, so you only get gradients for the current timestep.
If you want to backprop in time you can always detach at a certain interval! For this to work correctly I think you need to do something like this:
detach_interval = 5
for i, batch in enumerate(data):
    input, target = batch
    pred = model(input)
    loss = criterion(pred, target)
    if i > 0 and i % detach_interval == 0:
        loss.backward(retain_graph=False)
        # Here you need to detach tensors that will be reused next forward pass
        ...
    else:
        loss.backward(retain_graph=True)
    optimizer.step()

Note that you need to retain the computation graph when calling backward(retain_graph=True) if you are going to reuse tensors for next forward pass without detaching them. On the last backward() before detaching, you can let the backprop clean out the graph.
Hopefully this makes sense!