What a pair these are: they sound identical and look nearly identical and both have meanings that relate to government. Mastering their use, however, is simple.
The key is this: capitol, the one with an "o," is very limited in use. It appears in the term Capitol Hill, and is used to refer to one very particular and famous building, to some other similar buildings, and, occasionally, to a group of buildings that includes those similar buildings. For all other meanings, the word you want is capital.
This means that in a state's capital city is a building or group of buildings properly referred to with the word capitol, with an "o." In this use capitol is synonymous with statehouse: both refer to the building or group of buildings where a state legislature meets. The phrase capital city utilizes capital because it refers to a city, not to a building or group of buildings.
Capitol with a capital "C" refers to the particular building in Washington, D.C. where the U.S. Congress meets. It often appears before other nouns in phrases like the Capitol building and Capitol police, and is very frequently used in the term Capitol Hill, which refers both to the legislative branch of the United States government as well as to the location of the Capitol building. The Capitol, like many state capitol buildings, has a rounded dome that is somewhat reminiscent of the top of an "o," which may help some remember the "o" spelling. Note that the word capital as used to describe an uppercase letter, like in the phrase capital "C", utilizes capital.
The word capital has three distinct homographs, two for noun uses and one for adjective uses. Readers should consult those entries for the various meanings of capital, but can be assured that they all end in al, rather than ol.