St. Thomas Aquinas, in his Expositio in orationem dominicam a. 6, explains "and lead us not into temptation":
But does God lead one to evil, that he should pray: "Lead us not into temptation"? I reply that God is said to lead a person into evil by permitting him to the extent that, because of his many sins, He withdraws His grace from man, and as a result of this withdrawal man does fall into sin.
Related to this is St. Thomas's explanation of how God could have given the Romans up "to the desires of their heart, unto uncleanness, to dishonour their own bodies among themselves" (Rom. 1:24), because it seems this would mean He forced them to commit acts sodomy and thus to sin. He quotes James 1:13 in his Commentary on St. Paul's Letter to the Romans c. 1 l. 7:
But since impurity of this kind is a sin, it seems that God would not give men over to it: God himself tempts no one to evil (James 1:13).
The answer is that God does not give men over to impurity directly, as though inclining a man’s affection toward evil, because God ordains all things to himself: the Lord has made everything for himself (Prov 16:4), whereas something is sinful through its turning from him. But he gives men over to sin indirectly, inasmuch as he justly withdraws the grace through which men are kept from sinning, just as a person would be said to cause another to fall, if he removed the ladder supporting him. In this way, one’s first sin is a cause of the next, which is at the same time a punishment for the first one.
To understand this it should be noted that one sin can be the cause of another directly or indirectly: directly, inasmuch as from one sin he is inclined to another in any of three ways. In one way, when it acts as a final cause; for example, when someone from greed or envy is incited to commit murder. Second, when it acts as a material cause, as gluttony leads to lust by administering the material. Third, when it acts as a moving cause, as when many repetitions of the same sin produce a habit inclining a person to repeat the sin.
Indirectly, when the first sin merits the exclusion of grace, so that once it is removed, a man falls into another sin. In this way the first sin is the cause of the second indirectly or incidentally, inasmuch as it removes the preventative.
It should be borne in mind, however, that sin as such cannot be a punishment, because we suffer punishment against our will, whereas sin is voluntary, as Augustine says. But because sin has certain features contrary to the will of the sinner, it is by reason of them that a sin is called a punishment of a previous sin. One of these features is something preceding the sin, as the withdrawal of grace, from which it follows that a man sins. Another is something that accompanies the sin either interiorly, as that the mind is disarranged; hence Augustine says in Confessions I: you have commanded it, O Lord, and so it comes to pass that every disarranged mind is a punishment to itself; or in regard to its outward acts, which involve difficulties and labors, as sinners aver: we journeyed through trackless deserts (Wis 5:7). The third feature is something that follows the sin, such as remorse of conscience, bad reputation, and so on.