The Angelic Doctor wrote, Then when he says, if we deny him, he will also deny us, he shows what will follow as punishment. But there are two ways in which a person can sin against faith: first, by denying it openly; second, by rejecting it inwardly. In regard to the first he say, if we deny, namely, before others, he will deny us in the judgment: amen, I say to you, I know you not (Matt 25:12). To deny is not to know them to be members of his flock. In regard to the second he says, if we believe not, if we expel faith from our hearts, he continues faithful, i.e., he keeps his own faith; hence a believer remains in his faith, because faith is nothing less than partaking of or clinging to the truth. But he is the truth which cannot deny itself.
“Is he then not omnipotent? I answer that he is omnipotent, precisely because he cannot deny himself. For to be able to fail pertains rather to impotence; for the fact that someone loses some being is due to the weakness of his power. But for Christ to deny himself would be to lose something of himself; consequently, the fact that he cannot deny himself is an aspect of his perfect power. Hence he can neither sin, as has been said, nor deny his power and his justice, when punishment must be inflicted: he that believes not shall be condemned (Mark 16:16).” (2 Tim Super II ad Timotheu, C. 2, L. 2, 56-57)
In short he is describing the veracity of the Truth himself, the Word. We are cast out by our own unfaithfulness, inwardly or outwardly. The truth is the truth, we cannot change him, nor can he deny himself. The Angelic Doctor goes on to the say (within isolation of the verses mentioned by the OP) that God can remit punishment by the order of wisdom, but not by the order of wisdom and justice. I say in that respect the beatitudes such as Blessed are the merciful.