Here's how it works: If you are their liege, the gains from the war are part of your kingdom. It doesn't matter if they're your king, duke, earl, or even mayor, bishop, or count.
To claim a duchy from somebody else through war (when you don't have a casus belli that lets you claim it directly):
Find out who* has a claim on it by opening the duchy information screen and clicking on "Claimants" to see who has a claim on that kingdom.
Invite one of the male claimants over to your court. (If nobody will come over, or there are no male heirs, you'll have to find another way to get that duchy. Note that if one of your courtiers marries a female claimant that you can't legally give a title to, that female claimant is not your vassal and the newly-conquered duchy will not become part of your kingdom, even if you give your male courtier a title.)
Give that claimant a landed title. Any landed title will do, even a city, church, or castle.
Note that if you land the claimant a city, gaining him a Duchy will found a vassal merchant republic instead of gaining you a new feudal vassal if you are playing version 1.9 of the game or later. Merchant republics are generally considered awesome to have as vassals due to their revenue and tax bonuses, but this might disrupt an existing merchant republic that is already earning you revenue.
Go to war with the ruler of your choice, using the "Claim on duchy X" as your casus belli.
Once you win the war, that claimant will be your duke.
I'm guessing that this will also work with kingdoms if you're an emperor. So far, I've claimed two duchies this way: once by giving away a county to the claimant, and once by giving away a bishopric.
*As revealed in this other answer, you can't actually press the claim in war unless the claim is strong, or the claimant is a pretender (2nd or 3rd in line), or there's already another war going on over the title, or the current holder of the title is a woman (and you have a male claimant) or a child (so there's a regency). You can only use "any claimant with a pulse" if the title is disputed or the ruler is a child; you can only use "any male claimant with a pulse" if the ruler is female; otherwise, you'll need to pick up one of the pretenders or someone with a strong claim: you'll need to do slightly more research to find who they are, and they're often harder to invite to your court.
(Note: if there are three or fewer male claimants, then it's almost certain that they're the heir and pretenders. Just grab one and go on your way. Figuring out the exact claims is more important when there are four or more male claimants.)
Finding out why they hate you
To find out why people don't like you, hover over the opinion number to find out why: (alas, the cursor isn't showing in this screenshot. I assure you, it's hovering over the number.)
You can find out why people don't like you from any screen that shows their opinion number. Here's another example:
Doing something about them hating you
Vassals often rebel because they don't like you. Once you've worked out why they hate you, try to do something about it. If you have 98% of the titles in a realm, then, as you mentioned in the comments, they probably think your demesne is too large. (Fun fact: "demesne" is actually pronounced like "domain." Language is weird.)
To fix both of your problems (demesne too large, nobles hate you when you give out a title), you need to give out a lot of titles at the same time. Your demesne limit is in the upper-right corner of the screen; for you, it probably says something like "20/5", which means your demesne limit is 5, and you have 20 titles. The "20" will be red, and there's probably a notification at the top of the screen talking about that (unless you made it go away).
You need to do three things:
- Pause the game
- Give away all your excess titles, until you're within your demesne limit.
- Give away some excess duchies, until you're down to 2. (You get -10 opinion against all of your vassals per duchy above 2.)
If you can, arrange it so that you have 2 duchies, and all of the counties within those 2 duchies, and you're within your demesne limit. Spread out the titles a bit, so you don't have one Super Duke who's going to challenge your power.
There's some other advice for preventing revolts over at this other Arquade answer, but this will get you started.
Many thanks to @svick for figuring out the actual problem here.
(As a side note, you probably also have some note about being the "wrong holder type" for your titles. You're a noble, you'll get the best benefit from holding castles (i.e., baron titles) and counties (count/earl titles). Give away your cities and churches to other people. (And when you hit your demesne limit, give away the baron titles and keep the count titles.))
Best Answer
A good option here is to just offer white peace. Your opponent accept it far earlier and it only gains you 50 prestige less than winning the war would. If you intend to raid with your peace time then you will surely make up the 50 prestige with the raids you are able to do.
However if you give them white peace they will retain their causum belli, meaning they might, in the future attack you again with no armies and holdings.