First, you have to be careful to not confuse compounds themselves with the orthography for compounds. What you're asking about is the orthographic variation in how compounds are represented.
As far as orthographic variation goes, there has been very little research done in this area, most likely because there's been very little reason to think to look into it up until the internet age as, before now, written communication was limited to very few domains and so was likely to be far more influenced by standardization attempts than domains like texting or tweeting are.
So, there have of course been many attempts in many societies to standardize spelling, and these almost certainly play a role in why compounds are represented in one way or another, but actual use most likely varies along social dimensions. For example, those living in one region might tend to spell compounds in one way while those living in another region might spell them a different way. You can see regional variation even in standardization attempts, whereas there are British standards (e.g. behaviour) that differ from American standards (e.g. behavior). Other examples might be people of different age groups spelling them different ways or people of different ethnic backgrounds.
A good correlate to look at to better understand why a compound would be spelled one way or another is studies on phonological variation in sociolinguistics, of which there is a massive literature starting from Labov (1966) and continuing to the present day. The same approach can be taken to orthographic variation, including how compounds are spelled, and there are some signs of that happening (see Tatman (2016) or Eisenstein (2015), for example), but as of yet, the best anyone would be able to tell you are the invented rules of some prescriptivist grammarians, which are really just suggestions, not explanations of why things are the way they are.
Eisenstein, J. (2015). Systematic patterning in phonologically-motivated orthographic variation. Journal of Sociolinguistics, 19(2), 161–188. https://doi.org/10.1111/josl.12119
Labov, W. (2006). The Social Stratification of English in New York City (2nd ed.). Cambridge, England: Cambridge University Press. (Original work published 1966)
Tatman, R. (2016). “I’m a spawts guay”: Comparing the Use of Sociophonetic Variables in Speech and Twitter. University of Pennsylvania Working Papers in Linguistics, 22(2). Retrieved from http://repository.upenn.edu/pwpl/vol22/iss2/18