It is sort of a chicken and egg question. Before I started to think (maybe too much), I just assumed that Chinese characters had their own independent meaning and got chosen in certain compound words because of this, but maybe in some cases it's the other way around?
Most compound words in Chinese appeared later on in the history of the language. In ancient Chinese, just about every single character had it's own meaning. Later on when the language started becoming more modern, many words became compound words to simplify the language by making it easier to differentiate homonyms and to make the language sound more fluid when spoken. I've had a teacher explain that Chinese people feel that characters sound more natural in pairs.
I don't know the exact history in how the compound words were created, but having studied some ancient Chinese, I can say that the individual characters came first :) .