The Old Law contained some moral precepts; as is evident from Exodus 20:13-15: "Thou shalt not kill, Thou shalt not steal." This was reasonable: because, just as the principal intention of human law is to created friendship between man and man; so the chief intention of the Divine law is to establish man in friendship with God. Now since likeness is the reason of love, according to Sirach 13:19: "Every beast loveth its like"; there cannot possibly be any friendship of man to God, Who is supremely good, unless man become good: wherefore it is written (Leviticus 19:2; 11:45): "You shall be holy, for I am holy." But the goodness of man is virtue, which "makes its possessor good" (Ethic. ii, 6). Therefore it was necessary for the Old Law to include precepts about acts of virtue: and these are the moral precepts of the Law. [ST I-II, Q99, A2; emphasis added]
We must become holy in order to become God's friends. Consider: does it make any sense whatsoever to suppose that we can come to Christ for justification, but then spit in his face by living however we choose? Of course not. If we love him, we will keep his commandments (Jn. 14:15).
But – precluding the objection of those who will foolishly claim that this obedience makes our salvation "works-based" – Aquinas continues:
As Augustine proves (De Spiritu et Litera xiv), even the letter of the law is said to be the occasion of death, as to the moral precepts; in so far as, to wit, it prescribes what is good, without furnishing the aid of grace for its fulfilment. [ibid., ad 3]