In its most basic form, to win you need to build the Apolistic Palace, which requires knowledge of theolgy (best obtained with Oracle)
To build AP you must be in a state religion, and the city you want to build it in must have that reliogion.
Once AP is finished, then the religion you were in on the turn ofcompletion is now the AP religion. The AP religion cannot change.
Every civ that has the AP religion gets to vote, if they have the AP religion as their state religion the votes are doubled, and they are now eligible for AP leadership & victory. Each city that has the AP religion has its population added to the total votes.
Once all civs have at least one city with the AP religion, this makes the victory vote possible. The AP leader gets to select what is voted on.
Most leaders need to be at +8 relations with you to vote your victory.