No you can't just blame it on the Dems. On one hand the Dems didn't want to fund them, but Trump has also been keeping the migrants in these facilities under these conditions knowing he doesn't have the funding by congress to do so safely. And where are the courts in all this?
Well it is a thorny knot only made possible by the US system. The president has the authority to handle the migrants and the president decided he wanted to detain them. There is absolutely nothing wrong with this policy in principle because lots of countries (including Europe) detain asylum seekers while their cases are being assessed. But Trump has a problem because he did not have the money to provide proper facilities and congress refused to provide funding. So what should happen? Should Trump abandon his completely legitimate policy of detention and just let them go because congress does not provide funding? Should congress be expected to provide funding so Trump can ensure the detention centers have adequate resources?
Trump choose deal with the stalemate by running the centers without adequate funding and we see the results. If the courts did what you said they would be basically handing the dems a political victory which would outrage the many American voters who do not want to see asylum seeks automatically allowed to run free simply because the dems refused to cooperate. Of course, the courts could also order congress to provide funding which would outrage dems that want the centers closed. There is no simple path for court intervention.
Basically, in this story part of the blame lands on the dems who refused funding even after it was clear that Trump was going to detain people no matter what they did. They also deserve credit for belatedly realizing the error of the ways and fixing the problem.