The person who builds the UN gets 2 votes for themselves, the other civilizations will all vote for themselves UNLESS they were wiped out and then had a city liberated, in which case they will always vote for their liberator. Let's say Germany captures all of Rome's cities, Rome is eliminated from the game. But then Egypt comes and takes one of their cities* back from Germany, and chooses to liberate it, rather than puppeting or annexing. Rome comes back into the game, and will vote for Egypt in a UN election.
More importantly, the City-States also get a vote, and they will vote for whoever has the most influence with them UNLESS captured by a civ, then liberated by another, in which case they'll always vote for their liberator regardless of influence. If you've built some cities that are bringing in a lot of gold, you'll be able to win over most if not all of them with 500/1000 gold, especially if you go down the Policy tree that improves City-State bonuses.
I'm not sure how many votes you need for victory, I think it's determined by map size, or total civs and city-states.
So it's a viable option, I've gone for it myself in games but not been successful yet
* It might have to be their capital, I'm not totally sure, I've only read about it, not actually done it.