The ruling came at an emergency hearing on a lawsuit filed by two condemned inmates, child killer Tommy Lynn Sells and rapist-murderer Ramiro Hernandez Llanas, who are scheduled for execution next month.
TheTexas Department of Criminal Justice did not immediately say if it would comply and reveal where it obtained the pentobarbital.
"The ruling signals - as other courts have done recently — that it is unacceptable to keep prisoners or the public in the dark regarding how executions are carried out — including the source of the drugs," said lawyer Maurie Levin, who represented the prisoners in court.
"The condemned must have clear information about the drugs to be used, so that the courts can make an accurate assessment of the viability and constitutionality of any impending execution."
Levin said the details will be released under protective order to the inmates' lawyers. Whether they should also be disclosed to the general public will be decided at a later date.
Texas and other states want to keep the names of the compounding pharmacies they use under wraps to protect them from legal hassles and protests.
Texas' own attorney general ruled in 2011 that prison officials must release the information, and the court forced them to comply.
The development in Texas comes a day after an Oklahoma judge ruled that state's law protecting the anonymity of the drug suppliers is unconstitutional — which could put executions on hold while appeals wend their way through the courts.
Defense lawyers say they have to know the names of the pharmacies so they can investigate whether the chemicals they provide would violate the constitutional protection against cruel and unusual punishment.
— Tracy Connor
Copyright 2016 Nexstar Broadcasting, Inc. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.