Ich träume von meinem Bruder mehr als dem meiner Freundin.
Ich träume von meinem Bruder mehr als von dem meiner Freundin.
I think that second Bruder is omitted avoiding repetition, but the dem not; so what is its function in grammar?
Dem is a demonstrative pronoun here that just by coincidence looks like the article. Just like the noun it refers to it is in Dative case because of the preposition von.
Though leaving the von out the second time would theoretically make sense, it doesn't really sound right to my ears. Consciously, I am able to process it and carry the von over, but by itself it is not strong enough and I don't feel it. There are other sentences though where the preposition can be left out without a problem.
Fährst du mit dem Auto oder (mit) der Bahn?
Ich habe meinem Chef von dir und unserem Urlaub erzählt.
It seems to work for und and oder but not for als. And as soon as other words come into play it starts to fall apart.
Ich habe meinem Chef erst von dir und dann später von unserem Urlaub erzählt.
I wouldn't leave the von in that last sentence.
The first sentence is not correct (it does not make sense), the second one is. There are two different things to consider:
Repetition of "von":
"von etwas träumen" is similar to the English "to dream of sth". If you dream of someone or something (rather than just dreaming), you have to include the "von" the same as you would in English. Thus the first sentence is incorrect: The literal translation would be:
I dream more of my brother than of the brother of my girlfriend.
Repetition of "dem":
"dem" is the Dativ case (or Wikipedia) of the masculine definite article ("the brother" in English, "der Bruder" in German). The word "dem" without the context of a noun does not make sense and does not exist. Thus, if it is clear what that noun that is it can be omitted. However, adding the noun is never wrong.
In this case it is just avoiding repetition of the word brother, as in the literal translation:
I dream more often of my brother than of the (brother) of my girlfriend.
but as the German "dem" only makes sense with a noun it can be omitted if it is clear what that noun should be.
Note that the following sentence would also be correct:
Ich träume von meinem Bruder mehr als von dem Vater meiner Freundin.
where I just replaced the second "brother" with "father", both masculine objects.