After the Spanish Conquest, Costa Rica (Veragua in those days), as it formed part of Nicaragua and Panama; wasn't a popular destination for settlers due to the harsh lifestyle and no gold was found in comparison to the territories of Peru or Mexico.
Also, the geo political situation was tense as Mexico and Central America were liberating from Spain. Factions of Liberals and conservatives formed and had conflict in various sectors. In Nicaragua, Leon and Granada who were separate factions argued over the creation of a constitution and rights instead of authoritarian style government. Similar quarrels were present between San Jose and Alajuela against Cartago and Heredia in regards to independence versus uniting to the Mexican Empire.
The District of Nicoya was governed by Grenada and Leon who were distracted by their civil war. Santa Cruz and Nicoya voted to annex themselves to Costa Rica. Under the Nicoya Party they were under the banner of, "From the country by our will...", and without force joined Costa Rica escaping the anarchy of Nicaragua. This led to war between Nicaragua and Costa Rica and a Guatemalan conservative was trying to unite all Central America. Costa Rica was not in favor of this and wish to remain independent.
The US sent envoys to assist the effort in creating a Central American Federal Republic, but the effort failed and Special Ambassador to Central America John Stephens reported to Washington that the mission failed. Civil war continued throughout the region.