Justice Felix Frankfurter wrote the majority decision; in doing so, he relied primarily on the "secular regulation" rule, which weighs the secular purpose of a nonreligious government regulation against the religious practice it makes illegal or otherwise burdens the exercise of religion. He identified the Pennsylvania flag-salute requirement as an intrinsically secular policy enacted to encourage patriotism among school children.

What function according to the supreme court did the flag salute serve? Let's have some stream of consciousness first.
To answer the question, consider the following: He identified the Pennsylvania flag-salute requirement as an intrinsically secular policy enacted to encourage patriotism among school children. So, the answer is encourage patriotism among school children.