If you are in the fight you get experience for the kill. You don't need to get the death blow, or even do damage to a particular opponent.

If a character is dead, they don't get the XP. If they are out of combat but alive, they do.

Companiuons have a starting level, but if you are higher scale to your level. If you hire the first 2 companions (level 3) and fire one, go get some XP (to level past 3) and rehire them, they will be at your XP level.