It’s been a long time since I paid any attention to Costa Rica (sorry guys, I live nowhere near and can’t really afford to visit, and your country doesn’t have a direct impact on my life).
However, I was under the impression that they were big on free standard education and a good hunk of their economy was based in eco-tourism. And despite there being poverty, the place was in good enough shape the locals had less-than-nice opinions about migrant laborers from neighboring nations coming in and taking work for low pay. Presumably that means that economically, their policies were going fairly well.
I have to assume that based on the combination of eco-tourism and average education levels, enough people figured out that keeping things lush and green for long term profit was better than burning things down for short term gains that it was politically palatable.