There were several reasons why Los Angeles didn’t make sense as the capital after California became a US territory, including the major one mentioned by Joe Roberts: the Gold Rush, which occurred shortly after the Mexican-American War and propelled California into quick statehood, shifted the population center of California decisively to the north for the rest of the 19th Century. Los Angeles passed San Francisco to recover the title of California’s largest city in 1920, 70 years after statehood and the creation of the capital at Sacramento, thanks to early twentieth-century development surges.
State capitals in the United States were not generally placed in large cities, but rather on important transit routes at the time, which tended to be rivers.
Sacramento was not the state’s first capital. It started with a look at where people were and what was going on in the economy. Los Angeles was not a huge metropolis at the time. Until some individuals began bringing water in from Northern and Eastern California, it was primarily a desert.
It was proposed in the late 1800s that the capital be moved from Sacramento to Acton, California, which would have made far more sense than Los Angeles at the time, because Acton was experiencing a mining boom (while the Sierra foothills were experiencing a slump), and Acton was centrally located between the current wealth of mining and the growing wealth of the LA Basin and Central valley agriculture industry.