The court said it would allow both claimants to “possess, transport and use cocaine” but not sell it, according to Mexico United Against Crime (MUCD).
MUCD, which seeks to end the country’s “war on drugs”, called the ruling a “historic step”.
The decision must be reviewed by a higher court before it is enforced.
MUCD said the Mexico City court ordered the country’s health authority, Cofepris, to authorise the two claimants’ use of cocaine.
A Cofepris official told the AFP news agency that it had taken steps to block the court order, which was handed down in May. The official said that such authorisation would be outside of its legal remit.
The ruling will only come into effect if a panel of judges side with the original decision. If they do approve the ruling, it will only apply to the two people who brought the cases, whose identities were withheld.