I don't think the capital is chosen at random. The game seems to choose among the biggest cities. I don't know for a fact, but I assume there is some algorithm the pick the "best" remaining city. Perhaps based on population, production, science, gold or some combination of factors.