Forestry officials told reporters they tried to take the young whale out to sea several times but it kept returning to shore.
The whale was spotted on Manzanilla beach late Thursday and died early Friday. A necropsy is planned.
Melon-headed whales live deep in tropical waters and feed largely on squid. They can grow to nearly 10 feet (3 meters) long and live up to 30 years.