Is the following sentence grammatically correct?

Tom behaves the more politely of the two.
Yes, it's fine.
Thank you very much for your answer. Could I ask again?

All the examples I have come across of this "the COMPARATIVE of the two" pattern are those using adjectives, not adverbs.

a. The older of the two boys is in college.
b. Of gold and silver, the former is the more precious.
c. About half the students were from Asia, and those were the more industrious.
d. Which is the cheaper of the two?

The reason they all have "the" before COMPARATIVE is, in my theory, because "one/ones" are omitted or hidden after that. Thus,
a' The older (one) of the two boys....
b' .... is the more presious (one).
c' ...and those were the more industrious (ones).
d' Whis is the cheaper (one) of the two?

In short, the reason for "the" is because "the COMPARATIVE" is acturally a noun phrase which is specific and thus requires a definite article.

However, when the comparative is that of an adverb, you can't fill in one/ones after the comparative;
*Tom behaves the more politely (one) of the two boys.
The reason is quite obvious: it is not a noun phrase.

Question: how do you explain the definite article before the COMPARATIVE using an adverb?
Students: We have free audio pronunciation exercises.
Here's my reasoning against having the "the".

John behaves more politely than Alex.
Of the two, John behaves more politely.
John behaves more politely of the two.

I don't know why we'd need to put a "the" in there. It must surely be disposable.
Dear Ryan,
Thank you for your easy explantaion for the disposability of the "the."

Then, is the sentence in question grammatically wrong, or do you say
that although the sentence is regarded as correct, its "the" can be
disposed of? I'm a bit confused.
Hi Kamo Shushoku, welcome to the forums.

Your sentence is grammatically correct and so is Ryan's.
In your example, the comparative is used instead of the superlative. As you may have already known, the comparative there is used exactly like the superlative with no difference in meaning. So in this case, the rules for using the comparatives follow the ones of the superlatives.
We usually use 'the' with superlatives, and it is NOT only used with superlative adjectives but also with superlative adverbs as well (in your sentence it is 'more/most politely'). However, in an informal style 'the' is sometimes dropped before superlative adverbs. That is why both versions are correct grammatically with the latter (the one without 'the') being more colloquial.
As for the reason why we use 'the' with superlatives (or comparatives in your case), it is because there is normally only one best, biggest, etc individual or group so it is clear which one(s) we are talking about.

Students: Are you brave enough to let our tutors analyse your pronunciation?
That was quite an impressive explanation, Sir. I think I understand this pattern of "the comparative of the two" very well.
Thank you very much for all of you who have helped me greatly.