I cover the history of interpretation of this phrase whenever I teach Pauline Epistles and thought I'd share some what I give to my students here.
The view that "works of the law" relate to the ceremonial precepts is found as early as Origen:
“One should know that the works which Paul repudiates and frequently criticizes are not the works of righteousness [opera iustitiae] which are commanded in the law, but those in which they boast who keep the law according to the flesh; that is, the circumcision of the flesh, the sacrificial rituals, the observance of Sabbaths and new moon festivals [cf. Col 2.18]. These and works of a similar nature are the works by which he says no one can be saved, and concerning which he says in the present passage, ‘not on the basis of works; otherwise, grace would no longer be grace.’ For if anyone is justified through these, he is not justified gratis. But these works are by no means sought from the one who is justified through grace; but this one should take care that the grace he has received should not be in him ‘in vain’ [cf. 1 Cor 15.10] . . . So then, one does not make grace become in vain who joins works to it that are worthy and who does not show himself ungrateful for the grace of God. For anyone who sins after having attained grace becomes ungrateful to him who offered the grace.”—Origen, Commentary on Romans 8, 7, 6. Cited from Thomas Scheck, Origen and the History of Justification: The Legacy of Origen’s Commentary on Romans (Notre Dame: University of Notre Dame Press, 2008), 48–49.