that answer is in VoU's piece 1. for single player:
it's basically, city with no religion. if all cities have religion, city with fewest number of religions. note that whether it's a holy city for a religion does not matter, just if it has a religion. if all cities have the same number of religions, including zero, ties go to the highest population city, and i think to the older of two tied exact same number of religion, same population cities. you then take those factors and throw them in to wrestle with the RNG a little bit and see what comes out.
your capital will never be the holy city once you have another city. it's theoretically possible, but you add up all the factors for all the cities, and the capital's result is divided by 8 before it compares them. so fat chance there.
if your empire is smallish and you're about to settle what you know you want to be holy city wall street ville, make sure your other cities have a religion in them already if that's possible. if you want to try for a double holy city, get as many religions as you can to the OTHER cities but not your target holy city, and keep target holy city's population high and get the other cities populations low right before you found the religion. and then hope the RNG does what you want it to do. it doesn't always work for me, but it does quite often, often enough that i put particular effort into it and do take a risk at delaying a tech a turn or even two

sometimes to get to the double.
i don't read code, this is my understanding of the code from reading people's explanations of it and my own observations of the game. VoU does read code, and will step in to correct me where i'm wrong i hope!