Detach is used to break the graph to mess with the gradient computation.
In 99% of the cases, you never want to do that.
The only weird cases where it can be useful are the ones I mentioned above where you want to use a Tensor that was used in a differentiable function for a function that is not expected to be differentiated. And so you can use detach() to express that. But this is a rare case.