Then, when he says, now if I do that which I will not, he concludes to what he had previously proposed, saying, now if I do that which I will not, it is no more I that do it, but sin that dwells in me. This, too, has been explained earlier.
But it should be noted that in virtue of the same middle term, i.e., which I will not, the Apostle concludes to the two things he had proposed above, namely, the goodness of the law, when he said, now if I do that which I will not, I consent to the law, that it is good, and the dominion of sin in man, when he says here, now if I do that which I will not, it... is no more I that do it, but sin that dwells in me. The first of these conclusions pertains to his statement that the law is spiritual; the second to the statement: but I am carnal, sold under sin. But he draws the first conclusion, which is about the goodness of the law, from that middle term by reason of I do not will, because his mind does not want what the law forbids, which shows that the law is good. But in virtue of the phrase that I do he concludes that sin, which functions against reason's will, holds sway over man.
Source: Commentary on Romans