Without a picture, I cannot see the context in which the flag was carried (e.g. proudly waving it, or carrying it neatly folded).
Assuming the German soldier wasn't proudly waving it; could he not be taking home spoils of war? Just because Germany lost the war does not mean that no German regiment ever won a battle.
From the same World War II, plenty of US forces returned home with swords that they had looted from fallen Japanese soldiers. Although the US won the war and Germany did not; the principle remains the same.
Edit You added the context of the flag carrying, so I'll updte my answer accordingly.
There are two points of view here. The Danish soldier's and the German soldier's.
The Danish soldier has presumably interpreted the Danish flag being carried by the German soldier as a trophy. He think the German soldier is taking this flag home, because he managed to loot it from somewhere, and it is a memory of something important (most likely a victory against the Danish).
The German soldier's point of view; from your description, is not clear. Maybe he was carrying it as a trophy. Maybe he was carrying it out of respect for the Danish (not every soldier is as hostile towards their enemy; some may even not agree that the Danish are enemies).
I don't think the movie particularly wanted to explore the German soldier's point of view; it was focusing on the Danish soldier's behavior, and how the German soldiers chose to react to this (they did not; and simply marched forward like a beaten dog).