
979 So.2d 1110 (2008)
DEPARTMENT OF CHILDREN AND FAMILIES, Petitioner,
v.
B.N. and State of Florida, Respondents.
Nos. 4D08-717, 4D08-747 to 4D08-749, 4D08-751, 4D08-752.
District Court of Appeal of Florida, Fourth District.
April 9, 2008.
*1111 Jacob Jackson, Gregory D. Venz & John Copelan, Jr., Fort Lauderdale, for petitioner.
Howard Finkelstein, Public Defender, and Diane M. Cuddihy Assistant Public Defender, Fort Lauderdale, for respondents.
PER CURIAM.
These cases were brought to our court as six emergency petitions for writs of certiorari filed by the Department of Children and Families (DCF) and a petition for writ of habeas corpus not separately numbered, filed by juvenile B.N. Because all of the cases concerned the same juvenile in separate lower court cases and raised the same issues, we consolidated them. After ordering responses and replies, we issued an order granting the emergency petitions for writs of certiorari and quashing the trial court orders which had compelled DCF to take immediate custody of B.N. for secured placement for competency restoration services. We also granted B.N.'s emergency habeas petition and remanded to the trial court to order his release forthwith, subject first to consideration of Baker Act proceedings by the *1112 court and the parties. We indicated that an opinion would follow.
B.N. is a juvenile charged in several 2006 felony prosecutions in Broward Circuit Court's Juvenile Division. He was adjudicated incompetent to proceed and committed to DCF. The order stated: "The Judge requests the immediate placement of this youth to AFYC (Apalachicola Forest Youth Camp) due to the substantial risk of dangerousness he poses to himself and others." This order provided that DCF was to place B.N. in a treatment program to restore his competency pursuant to section 985.19(4), Florida Statutes.
When B.N.'s detention with the Department of Juvenile Justice was due to expire, the judge held a hearing on his future placement. He was advised that AFYC was the only residential facility for a juvenile declared incompetent and in need of secure placement for competency restoration services, and that it was at full capacity. There were other juveniles on a waiting list ahead of B.N. In orders entered on the same date in all of the cases involving this juvenile, the trial court directed DCF to take immediate custody of B.N. from the Department of Juvenile Justice upon the expiration of his juvenile detention holds, which would occur that day. This prompted the filing of the emergency petitions for writs of certiorari.
In its petitions for certiorari, DCF stated that AFYC had 48 beds for juveniles determined to be incompetent to proceed and who needed secure placement. It alleged that it had no other secure placement alternatives for juveniles declared incompetent to proceed, and that AFYC had a waiting list. B.N. was number eight on that list. It further alleged that B.N. was not in psychiatric crisis and had been receiving medication while in detention at the Department of Juvenile Justice. It alleged he was reportedly responding well. DCF argued that the trial court lacked authority to direct the immediate placement of a juvenile committed to the DCF as incompetent to proceed.
We granted the petitions for writs of certiorari and quashed the trial court orders because section 985.19(7), Florida Statutes, expressly limits the provision of competency restoration services for juveniles to available funding. See Dep't of Children & Family Servs. v. M.H., 830 So.2d 849 (Fla. 2d DCA 2002), rev. denied, 839 So.2d 698 (Fla.2003). We also agree with DCF's argument that the orders directing it to take immediate custody of B.N. constitute a violation of the separation of powers. Id.; see also State, ex rel. Dep't of Health & Rehabilitative Servs. v. Nourse, 437 So.2d 221 (Fla. 4th DCA 1983).
With respect to B.N.'s emergency habeas petition, we granted relief because petitioner had already completed 21 days of juvenile detention for his offenses, and his hold thus expired. Section 985.24(2)(d), Florida Statutes, provides that a juvenile alleged to have committed a delinquent act or violation of the law may not be placed into secure, nonsecure or home detention "[d]ue to a lack of more appropriate facilities." It follows that if a juvenile cannot be placed in such detention due to lack of more appropriate facilities, he surely cannot be held in that same detention once the statutory basis for his detention has expired, as occurred here.
We granted habeas corpus relief subject first to consideration of Baker Act proceedings under Chapter 394 by the trial court if appropriate, given certain findings by the trial court that petitioner was a threat to himself and others and to the community based on an escalating history of violence.
*1113 Certiorari granted, orders of the circuit court quashed; habeas petition granted, and petitioner ordered released forthwith, subject to consideration of Baker Act proceedings.
FARMER, GROSS and TAYLOR, JJ., concur.
