I noticed in several documentaries that the use of mercenaries by both the Catholics and the Protestants was mentioned several times. Back then, how were mercenaries organized? Did they have private companies with the soldiers on payroll like we have today? Did companies play both sides, or did their religion and birthplace/place of loyalty still play a factor in who they contracted to?
Interesting question, or rather questions. I'll pick it apart, piece by piece, and try to get you an understanding of Early Modern mercenaries during the Thirty Years War.
One thing about Early Modern warfare: mercenaries were the go to military unit between 1450 and 1650. The standing army is a thing of the mid to late 17th century. The mercenary-armies of the Thirty Years War slowly but surely turned into standing armies (a thing that is attributed to absolutist rulers - if and how absolutism is "real" or "questionable" is a different debate, for the purpose of this answer absolutism refers to a time period between 1650-1750 that is characterized by certain ideas of ruling and centralizing control).
To tackle your question we have to get one thing out of the way, certain ideas of loyalty that we attribute to place/country of birth (to die for your country) are a thing of nation states. They aren't necessarily a reflection of the Early Modern individual of the Thirty Years War. Home (if at all bigger than the house you lived in) was nothing more than the village you were born in. Social, economical and spatial mobility was rare, dangerous and, among the third estate, most of the time even unwanted. So did they have loyalty towards a place? Tough question; from one eyewitness report we know that a mercenary wrote about the destruction of Magdeburg. He wrote that it was sad to see it burnt to the ground and totally destroyed because it was his father's land. So there at least appears to be some sort of connection. What he deems worse is the fact that he cannot be part of the plundering, because of a wound he recieved before the city gates fell. So his priorities are clearly personal gain before "loyalty" of an uncertain degree. (This can be found in "HAGENDORF, Peter: Tagebuch eines Söldners " - literally 'Diary of a Mercenary'.)
Now on to the main part of your question, the organization of the mercenary armies. Being a mercenary was a way of life. A profession, like others. You were recruited by a professional recruiter that roamed the countryside and tried to get as many people as his army could pay to enlist (I do apologize, if anyone is more knowledgeable when it comes to English terminology, please correct me!). The army consisted of the mercenaries, paid men, that received their Sold (literally 'pay' - the German term Söldner is derived from the term for the payment, the Sold ) monthly, if the Kriegsunternehmer (literally 'military entrepreneur') leading them had the money on hand. The army was followed by the Tross (I have no translation on hand, but the term describes everyone following the army: families, cooks, Bader [simple doctors/surgeons], fencers, prostitutes, etc.) so whenever numbers of armies are mentioned they have to be at least doubled/tripled to get a feel for how many people were on the move through a territory. Keeping in mind that the HRE (Holy Roman Empire) had about 16 Million people living in it before the Thirty Years War started, an army with 30.000 fighting men becomes a whole lot bigger if you include the Tross ! The life of a mercenary was very dependant on the area he camped in (during winter season the mercenaries were appointed to local peasantry and lived under their roofs until spring came and the fighting continued. If the farmer had enough food, the winter was acceptable, if he didn't the mercenary had to hunger) and how good he was at plundering sacked cities. The rules of war included one that allowed a city that didn't surrender to be plundered completely.
The mercenary armies went under certain reconstruction during those thirty years. Wallenstein, one of the most known Kriegsunternehmer , followed the principle der Krieg ernährt den Krieg (literally 'war feeds war'). This means that while he was paid by the Emperor for his services, he used his local control over the territories he camped out in, to collect war taxes and Naturalien (literally 'natural produce'), to have his army be fed and supported by the local populace while also being paid for them. Until then only the contribution of food was the norm for an occupied territory. He also had the peasants in his territory make the shoes and weapons, powder and uniforms, to be able to support his own army without being dependant on the Emperor as the person to pay him. After his death in the early 1630s others followed suit and used the populations of the territories they camped in more and more. This economization of war led to something new: the armies that fought for e.g. a Catholic Kriegsunternehmer , like Wallenstein, might have camped out in a Catholic territory sucking dry their entire local economy and food support systems. To our knowledge the mercenaries didn't have a problem with this. Why would they? They followed their profession, which was being a soldier in wartime. Another interesting point to add here is the comparison of two diaries, one of a farmer the other of a mercenary (HEBERLE, Hans: Zeytregister - the farmer, and HAGENDORF, Peter: Tagebuch eines Söldners - the mercenary). While the farmers descriptions of the war are cluttered with religious symbolism and ideas, the mercenary has a lot less to say about religion. Instead he speaks about the military value of the area they are in, how a certain valley can be used for a strategic advantage, etc. He also talks about fighting for both sides, depending on who he was paid by.
This leads a problem that arises with your question: the lack of knowledge about the intrinsic motivation of the mercenaries. We have a diary of one mercenary. The armies were about as diverse as the general population. Some could read, less were able to write and most could do neither. But the systemic structure of the mercenary army leads to the conclusion that the personal motivation probably didn't play a huge role in the fighting. Being a mercenary was a job. To be able to live you needed the money and took it from either side. Loyalty to a certain Kriegsunternehmer is debatable but not likely. To my knowledge we have no definitive proof of it, but proof of the opposite, so we should accept that as the scientific knowledge we have on the topic until it is proven wrong.
To conclude it is safe to say, that the structure of the Early Modern mercenary army was comparable to what you have described in your question. The ruler of a territory, kingdom, etc. hired a Kriegsunternehmer that provided him with an army and fought for him as long as he was paid. During war this Kriegsunternehmer had the de facto power over the territory he camped in and used this power to enrich himself and his generals even more. This economy of war is thought of as one of the main reasons standing armies started to be the norm after the Thirty Years War for the rest of the Early Modern European period. It has also lead to the description 'warlord' for the Kriegsunternehmer, but this is a different discussion. The second part of your question is a bit harder to answer. The Kriegsunternehmer mostly fought for one side during the war, since their pay was almost certain. The simple mercenaries probably didn't and instead fought for whoever paid them at the time. It is also important to mention, that the mercenary armies of the Thirty Years War were insanely diverse (as in from many different places of Europe. There were soldiers from the Balkans, the British Isles, Eastern Europe, Western Europe, Northern Europe, etc. scattered all around the different armies).
If you want to read more about Early Modern Military and War "Geoffrey Parker" is a great point to start. While I'd disagree with some of his theses on the Thirty Years War as a whole, his knowledge of Military History is undoubtedly great. One place to start could be "PARKER, Geoffrey: Europe in Crisis. 1598-1648" or "PARKER, Geoffrey: The Military Revolution". A pretty good overview on the life of a mercenary during the Thirty Years War can be found (as far as I know only in German) in the book "GOTTHARD, Axel: Der Dreißigjährige Krieg" where he spends a lot of time of this introduction to the Thirty Years War on big parts of your question.
I hope this clarifies some of your questions and please feel free to ask me, if you want to know more.