When the Spanish colonies in America broke away from Spain they largely followed the political-administrative demarcations set down during the colonial era, as /u/mrjosemeehan said. Essentially, they tried to follow what we refer to as uti possidetis juris, which states that an independent state after breaking free of its colonial masters should only claim the same territories it had before independence.
This is a savvy self interested position to take for two reasons. First, it keeps a bunch of newly independent countries from declaring war on one another (though it happened anyway, e.g. War of the Pacific, countless wars in Central America, etc.). Second, because it prevents the atomization of states into tiny, fragmented, republics. This second reason is particularly pertinent in the case of Central America since that's exactly what happened to it.
First things first: The Capitancy General of Guatemala is not exactly what we know today as the republics of Central America. Panama, for example, was part of Nueva Granada (which later became Colombia). Part of Guatemala also joined Mexico fairly early on and remains Mexican territory to this day (Chiapas). So right off the bat we know that Central America today isn't exactly the same thing, territorially speaking, as the Capitanía General de Guatemala (which I'll just call Guatemala for the moment).
After declaring independence there was the important question of whether Guatemala would join Mexico or become its own country. Venezuela (which had also been a capitancy general) had united with the Viceroyalty upon which it had been dependent (Nueva Granada AKA Colombia), so there was already precedent for such a union. After independence, Mexico was already thinking about annexing Cuba (yes, I really had to throw Cuba in there somewhere), which had been a Capitancy General under Nueva España (AKA Mexico), so such unions were also already on Mexico´s mind.
Under the First Mexican Empire, Emperor Agustín de Iturbide (1821-1823) tried to persuade Guatemala to join, but that project crumbled as his own hold on power dissolved and his troops saw themselves needing to doubletime it home. Guatemala decided, instead, to become an independent republic.
The next few decades saw internal rivalries between local Central American elites, important economic issues, and general dissatisfaction, all degenerate into the political fragmentation which characterizes Central America today. Attempts were made to reunite them but these were obviously unsuccessful. The blow by blow of their fragmentation is full of a lot of back and forth, and honestly it has been a few years, but I can gladly point you towards some good bibliography.
As a good introductory text, I´d recommend Inevitable Revolutions by Walter LaFeber. It even gives you what was happening in each country in parallel.
You could also likely benefit from the pertinent article in Leslie Bethell's Cambridge History of Latin America series.
Regarding Mexico´s annexationist ambitions towards Cuba and (to a lesser degree) Guatemala, I´d try Rafael Rojas´ Cuba Mexicana. Historia de una Anexión Imposible. (sorry, this one is Spanish language only)