The story
Calque from Latin expressions such as equi dentes inspicere donati (“to inspect the teeth of a provided horse”) in St. Jerome's c. 400 Preface to the Commentaries of the Letter to the Ephesians (Commentariorum in Epistolam ad Ephesios Libri Tres), which designates it as a "common proverb" (vulgare proverbium). The ultimate referrent is inspection of horses' teeth as a way of ascertaining their age and value.
Etymology from Wiktionary, CC BY-SA 4.0.