Just found the problem. I misread the claims, turns out i only gained control of the duchies, not the land itself. Weird but not actually a glitch.
There are a variety of ways to go to war. When you declare war, read the Casus Belli very carefully. It turns out that while the Medieval and Renaissance eras didn't have a United Nations or equivalent, they did have to deal with similar fallout: if you went to war because you're a warmongering monster bent on conquering the world, the countries near you would probably form a temporary alliance and beat you senseless. Therefore, wars were usually fought for "valid"† reasons: somebody had a claim on a bit of land (discovered by carefully reading family trees‡, being a scholar of genealogy, and/or making one up!), because their opponents were heretics/heathens, or because they were rising in rebellion.
Some Common Cassus Belli
Here are a few common CBs and their results if you win:
- Your claim (possibly multiple): you get that county/duchy, and no others. Regardless of how many castles you siege and how many armies you destroy, you're only going to get the county/duchy that you went to war over. (You can go to war over multiple claims that you have at the same time, but not a combination of your claims and your vassals' claims.)
- Your vassal's claim: Once you win, your vassal gets the land (and loves you dearly). This will expand your kingdom, but it won't expand your personal demesne. (Note: if the title you're taking is equal to your rank, your vassal will become independent! If you're a duke, don't press your vassals' claims on duchies; if you're a king, don't press your vassals' claims on kingdoms.)
- A claim from a member of your court: When you win, that courtier is going to take over the title. If they have no other titles, then they're just going to be independent. (This is why, if you use courtiers' claims, you should give them some minor title first: a city, church, or castle is enough for them to still be your vassal afterwards.)
- Opponent is excommunicated: Once you win, your opponent abdicates, and his heir takes over. You'll only get things if you're the heir.
- De jure claim: You kingdom/duchy will definitely expand, but the title can go to one of three possible people. If it's the last county owned by someone, then they become a vassal (of you or your vassal, depending on who owns the duchy). If it's not their last county, then either you or your vassal gain the county.
- Wars over independence, deposing your liege, or refusing arrest (a.k.a. war against tyranny): In all cases, nobody gains anything. Deposing your liege just means his heir takes over, losing against tyranny just means you're arrested (and the liege, as a separate action, can revoke a title), and winning against tyranny just lowers the crown laws.
- Holy War: The person pressing the holy war takes the named title as part of their personal demesne, including all lower titles. If you wage holy war to take a duchy, you'll have plenty of titles to hand out afterward. (Again, if you destroy other castles/armies/kingdoms, you still only get the bit of land you mentioned in your initial Casus Belli.)
- Crusade/Jihad/Great Holy War: These are called by the leader of a religion, regarding a Kingdom. If the war is successful, the land is handed over to the noble whose armies contributed most to the war.
Why you might have lost everything on losing a war
On a separate note, when you lost your war, it would depend on what the war was about. If they had a claim on your duchy (I'm assuming you had a single duchy with three counties in it), then that's it: you lose everything. Also keep in mind that the holder of the duchy title can revoke counties, it just causes a hit to the duke's opinion with his other vassals. If he has no other vassals, then he can simply revoke everything and you're out of a job. Similarly, if they were simply deposing you, and you had no heirs, then that's it: your dynasty has ended. And if it was a Holy War for your last duchy/county, then surrendering means that you lose all of the titles in that duchy/county.
Footnotes
†: One historical example: in 1215, a bunch of English barons rebelled against King John. The barons won, but John remained King afterward; they just limited some of his kingly powers via the Magna Carta, a document that they made him sign. In Crusader Kings II terms, this is a War Against Tyrrany/Resisting Arrest, which reduces crown authority.
‡: One more example, because I can't resist: The Hundred Years' War was kicked off in 1337 at least partially because the King of England had a better claim on the Kingdom of France than the current King of France did!
Best Answer
Most likely what happened is that the "claim" on Denmark was not your personal claim, but that of one of your vassals. Since you cannot have a king as a vassal (I assume you are not an emperor), upon victory, your vassal gained the Kingdom of Denmark, became independent, and also took his existing land with him.
To avoid this in the future, pay attention to what and whom you're actually declaring war for! The tooltips on the declare war menu should clearly delineate what the potential outcomes of a war are.