Capital is wealthiest province inside the region of your primary title which has same culture and religion. Counties have always the same capital, duchies can move capital inside their primary duchy and kingdoms inside the primary kingdom. If you don't have province inside your primary title region then it will be richest province with same culture and religion. If you don't have same culture or religion province then it will be in the richest province.
For example if you want to move Swedish capital to Constantinople make sure that you don't have any provinces in Sweden or provinces which have Swedish culture or which are Catholic. Cultural conversation and religious conversation events can become handy. In my Kingdom of Sweden game where my primary culture was Finnish, my capital was long time in Catholic Finnish province of Novgorod (originally it was Russian Orthodox province) till Constantinople converted to Catholism and adopted Finnish culture, then my capital moved.
Moving capital inside kingdom is easier. If you want to move English capital from Wessex to Oxford you just have to make Oxford richer by building plenty of stuff there while you either ignore Wessex or give it away.