Gnashing (חרק) of teeth (שנים) appears several times in the Old Testament, including three mentions in Psalms, one in Job and one in Lamentations. Lamentations says, of the Babylonian occupiers of Jerusalem, "שָֽׁרְקוּ֙ וַיַּֽחַרְקוּ־שֵׁ֔ן," "They hiss (שרק can also mean to weep) and gnash their teeth". In all Old Testament instances, except Psalms 112:10, the gnashing appears to be an act of persecution and not suffering.
The phrase "(there shall be) weeping and gnashing of teeth" (in the Ancient Greek: ὁ κλαυθμὸς καὶ ὁ βρυγμὸς τῶν ὀδόντων) appears seven times in the New Testament as a description on the fate of the unrighteous ones at the conclusion of the age. It is thought to derive from a logion in the hypothetical Q source, which yielded Matthew 8:12 and Luke 13:28. The other five occurrences (Matthew 13:42, Matthew 13:50, Matthew 22:13, Matthew 24:51, and Matthew 25:30) are all within the context of parables and are widely held to be redactional additions by Matthew.[1] Others, however, such as some Biblical literalists, believe redactional theories of the parables are speculative at best, and offer little explanation as to the meaning of this phrase, and only speculate as to why Matthew and Luke included this apparently familiar saying.
The phrase "gnash the teeth" is found in Acts 7:54, in the story of the stoning of Stephen. The phrase was an expression of anger of the Sanhedrin towards Stephen before the stoning.
The pseudepigraphal book of 1 Enoch contains a similar, and earlier, use of the phrase in an eschatological context which is similar to its usage in the Gospel of Matthew.[2]
Olaf Rölver: Christliche Existenz zwischen den Gerichten Gottes. Untersuchungen zur Eschatologie des Matthäusevangeliums. V & R unipress Verlag, Göttingen 2010 (=Bonner Biblische Beiträge 163). ISBN3-89971-767-8 (German)
Benedikt Schwank OSB: „Dort wird Heulen und Zähneknirschen sein“. Verwendung und NichtVerwendung dieses „Bildes für Selbstvorwürfe“ bei den Synoptikern. In: Biblische Zeitschrift, neue Folge 16/1, 1972. S. 121-122. (German)