“Be detached from all sin, even venial sin.”
_______________
What does that mean, especially if you have leeway to go to confession afterwards?
That is a standard condition for any plenary indulgence. You can see that in this document from the Apostolic Penitentiary, The Gift of the Indulgence.
From my understanding, the meaning is that you have no attachment to sin...in other words, no desire, no pleasure from committing that sin and being repulsed by that sin.
One big thing to remember is that an indulgence is not a forgiveness of sin, it is a remission of purgatory for the effects of that sin. Purgatory is a place of purification (purga - purge; tory - place of). It is a grace that God gives us to purify our souls in preparation of encountering His divine presence face-to-face in heaven.
And as long as you have an attachment to any kind of sin, you need purgatory (Rev 21:27).
Think of the capital vices as an example of an attachment to sin: how many of us suffer from the capital vices of vainglory and pride? What sins result from those vices? Well, the sins are dealt with through contrition and confession; but the vices need to be dealt with as well.