There's no take over. All captains are assigned during OoB to their formations. And once they die, the formation loses all captain-specific perks. A new captain is not assigned during battle. So OoB assignments are final. So just to reiterate, whenever either a party leader/army commander/captain of a formation/sergeant as a player dies, there is no take over of the formations and party leader/army commander/captain-specific perk effects are lost immediately and no new perks get applied by some different NPC.
There are captain specific perks and party leader perks. Only the heroes assigned to a formation will give captain perks to that formation (this includes the player as well). Party leader perks are applied to all troops during battle so if player is the party leader and is not assigned to a formation, all the troops will get only the party leader perks. If the player is assigned to a formation it will give party leader perks to all troops and also captain perks to the assigned formation. There are also army commander perks that are very similar to the party leader perks but only apply when the player/hero is the army leader. Party leader and army commander perks apply to all troops and there can only be one party leader/army commander for each team.
In party battles, player is always the commander of their team so they control all formations in their team. So even if you assign a captain to a formation, it is still the player who gives orders to all the formations and captains follow (unless the player delegates command with F3+F4 or F6 on legacy).
In army battles, if player is the commander of the army the same rule applies. Though if the the player is a sergeant, they can pick a formation to lead. In this case the player can give orders to the formation it is assigned to and can't give orders to other formations.
And as an additional note, captains and party leaders are not affected by their own buffs, only their troops do. Heroes in general can, however, be affected by party leader/army commander/captain-specific perks of other heroes if they're in the same team/formation. It's just that they can't buff themselves with their own party leader/army commander/captain-specific perks, just personal perks.