What is the purpose of touching the tongue to the roof of the mouth when meditating
‘Suppose, with my teeth clenched and my tongue pressed against my palate, I beat down, hold back,
and crush the mind with mind.’
So, with my teeth clenched and my tongue pressed against my palate, I beat down, held back,
crushed the mind with mind. While I did so, sweat ran from my armpits.
It was just as if a strong man, holding a weaker man by the head or shoulders, were to restrain,
subdue, and attack him;
even so, with my teeth clenched and my tongue pressed against my palate, I beat down, held
back, and crushed the mind with mind, and sweat ran down my armpits.
But although I exerted tireless energy, and unremitting mindfulness was established in me, my
body was overstrained and lacking calm, because I was exhausted by the painful striving.
But, Aggivessana, such painful feeling that arose in me did not invade my mind and remain.
Mahā Saccaka Sutta.
If, bhikshus, while the monk is attending to the stilling of the thought-formation, there still arises
in him bad unwholesome thoughts connected with desire, with hate, or with delusion,
then with clenched teeth and the tongue pressing on the palate,
he should subdue, restrain, attack
the (bad) mind with the (good) mind.
With clenched teeth and the tongue pressing on the palate, those bad unwholesome thoughts are eliminated
and disappear.
By their elimination, the mind thus stands firm internally, settles down, becomes unified and concentrated.
Vitakka Saṇṭhāna Sutta
Teeth clenched and my tongue pressed against the
palate used to gain unremitting mindfulness in the 1st case during the Bodhisattva's self mortification. He finds himself only being exhausted by this, but in the latter case it is recommended as the last resort action drive out unwholesome thoughts.