He applies this simile when he says, "So we also, when we were children, were serving under the elements of the world."
First, he applies it as touching the Jews;
Secondly, as touching Christ (v. 4).
He says therefore: I say that as long as the heir is a child he differeth nothing from a servant; so, we Jews also, when we were children in the state of the Old Law, were serving under the elements of the world, i.e., under the Law which promised temporal things—"If you be willing, and will hearken to me, you shall eat the good things of the land" (Is 1:19)—and threatened temporal punishments....
Or the Old Law is called "element," because just as boys who are to be trained in a science are first taught the elements of that science and through them are brought to the fulness of science, so to the Jews was proposed the Old Law through which they would be brought to faith and justice: "the law was our pedagogue in Christ" (3:24). Or, under the elements, i.e., the corporeo-religious usages which they observed, such as days of the moon, new moons and the Sabbath. But one should not object that on this account they differed nothing from the pagans who served the elements of this world, for the Jews did not serve them or pay them worship; but under them they served and worshipped God, whereas the pagans in serving the elements rendered them divine worship: "They worshipped and served the creature rather than the Creator, who is blessed forever" (Rom 1:25). Furthermore, it was necessary that the Jews serve God under the elements of this world, because such an order is in harmony with human nature which is led from sensible to intelligible things.
Source: Commentary on Galatians