All foreign citizens entering Costa Rica must have a passport that is valid for at least six months after the date they enter the country.
For more information visit here.
A word to the wise: In years past entrance requirements were much less strictly enforced than they are today. Airline counter personal in the country of origin are responsible for enforcing entrance requirements. Although they may still occasionally be lax, if you do not have a passport that is valid for at least six months after your date of travel, it is highly probable that they will not let you board the plane.