Most countries have one capital, but a few divide the role between cities. The reasons are usually historical or political.
Bolivia
Sucre is the constitutional capital and seat of the judiciary, while La Paz is where the government and legislature sit.
The Netherlands
Amsterdam is the constitutional capital, while The Hague is the seat of the government, parliament and royal court.
South Africa
South Africa has three capitals: Pretoria for the executive, Cape Town for the legislature, and Bloemfontein for the judiciary.
Why it happens
Dividing functions can reflect a compromise between regions, respect for historical centers, or a decision to spread power across different cities.