Basic python and even coding.
You are overwritting variable called Y_prob which equals the older Y_prob but detached.
Your computations were calculated with previous one.
it’s like if you do
x=5
print(f'id x: {id(x)}')
w=[x]
print(f'id w: {id(w[0])}')
x=6
print(f'id new x: {id(x)}')

id x: 10914624
id w: 10914624
id new x: 10914656

When you overwrite x, it no longer points to the same object.
Analogously
x=tensor(5)
print(f'{X old: id(x)}')
x=x.detach()
print(f'{X new: id(x)}')