Turn your question around the other way: Is there some reason you think it's not legal ? Ie.: something you read saying that ? "Legal" seems to imply that a place needs express allowance. Eg.: a sign or law saying "metal detecting allowed here" type wording. On the contrary, if it's silent on the subject (ie.: not expressly dis-allowed), then presto: it's not illegal.
Metal detectors are a common site on all south american, mexican, and caribbean island tourist beaches. But sure, like anywhere in the world: If you asked enough resident archies, or travel consulates, etc.... Someone might couch your answer in terms of raiding the pyramids, exporting gold bars back across borders, shipwreck salvor, etc... And persons have been known to get a "no" to the question. Imagine their surprise when they arrive for their vacation, and see md'rs on the beach w/no issues ?
And even if you could find (via google word combination searches) something "dire" about Costa Rica: Read close and make sure you're not simply reading someone else's having been the victim of a "safe answer". Or an isolated scram from a single hotel front location, etc... Sometimes they return home and put "such & such off-limits" on a post. That leads to links, which leads to links, which leads to links, which all point to each other as their "proof". When it was just a fluke scram or silly answer in the first place. When THAT happens, it's merely impossible to "put to rest". Doh!
Rather than ask someone who gives a silly answer, you can always see who deals detectors in the country. All the major manufacturers have dealers around the world. And you can find their distributor's contact info on their websites usually. Contact whoever's closest to Costa Rica for the "real" skinny. But if it was me, I wouldn't bother. I'd just detect.