Summary:

If you take a city-state that has been captured by another civilization, you have the choice to annex the city-state, make it a puppet, or liberate it. If you choose to liberate a city-state, then it will always vote for you in UN elections, no matter what its relations are with you at the time of the vote. If the same city-state has been liberated twice, it will vote for the civ which liberated it most recently.
If a civilization has been removed from the game and you capture one of those civ's cities, you have the option of annexing it, making it your puppet, or liberating it. If you do so, the civilization returns to play. The liberated civ will always vote for you in UN elections. In case of multiple liberators, the civ will vote for whoever liberated them most recently.