That's true insofar as dealing with the Eastern Hemisphere. I don't know of any doctrine that would compel us to aid them in the event of invasion from e.g. anywhere else in Latin America.
The borders of Costa Rica are really close to the Panama Canal. If Nicaragua started to invade Costa Rica, I think America would put a stop to it really quickly to protect the Canal.
Could you link to a source for this. The relevant wikipedia article makes the same claim but is tagged [citation needed]. The LA times article linked by the parent says "(Costa Rica is presumably sheltered by the U.S., but only under the loose ties of the Organization of American States)" which is kind of vague and mysterious. All the countries of the Americas are in that organisation so that leaves the question of what would happen in a conflict between neighbours.
In essence, they have made themselves a client state.
I'm sure it's completely altruistic and not having to do with beneficial trade agreements.