My guess would be something like this: Prior to WWI, the beret was a dress uniform item only. Then, in the mud of Flanders, a French officer removed his helmet and put on his beret because Les Allemands ne coup pas merde! and everyone else followed suit.
After their buddies got shot in the head repeatedly, they went back to helmets, but the image stuck.