US magistrate judge Zia M. Faruqui in Washington, D.C, rejected Facebook's argument about protecting privacy as "rich with irony", Reuters reported, citing a copy of the ruling.
The judge also criticized Facebook for failing to hand over information to investigators seeking to prosecute Myanmar for international crimes against the Rohingya Muslim minority.
Facebook had refused to release the data, saying it would violate a US law that bars electronic communication services from disclosing users’ communications.
But the judge said the posts, which were deleted, would not be covered under the law and not sharing the content would "compound the tragedy that has befallen the Rohingya".
"Facebook taking up the mantle of privacy rights is rich with irony. News sites have entire sections dedicated to Facebook's sordid history of privacy scandals," he wrote.
A Facebook spokesperson said that the company was reviewing the decision.
"We remain appalled by the atrocities committed against the Rohingya people in Myanmar and support justice for international crimes," the spokesperson said. "We've committed to disclose relevant information to authorities, and over the past year we’ve made voluntary, lawful disclosures to the (Independent Investigative Mechanism for Myanmar) and will continue to do so as the case against Myanmar proceeds.”
More than 730,000 Rohingya Muslims fled Myanmar's Rakhine state in August 2017 after a military crackdown that refugees said including mass killings and rape. Rights groups documented killings of civilians and burning of villages.
Myanmar authorities say they were battling an insurgency and deny carrying out systematic atrocities.
Gambia wants the data for a case against Myanmar it is pursuing at the International Court of Justice (ICJ) in the Hague, accusing Myanmar of violating the 1948 U.N. Convention on Genocide.