Much of Costa Rica is covered by rainforest so expect rain at any time of the year, but there is a dry season on the Pacific coast that runs from December to April and a wet from May to November with the heaviest rainfall being in September and October.
It is harder to define the seasons on the Caribbean coast though it tends to rain less between March and September. Generally the best time to visit is between December and April.
The only time we would actually recommend not travelling would be September and October.