There are two completely disctinct issues here: a purely ethical one and then a legal/logical one.
The ethical issue is whether chimps should be granted some degree of protection against being treated badly (in ways that its likely they find unpleasant) that we do not grant other non-human animals.
The completely separate issue is on what basis should we enforce this societal rule. There are countless ways it could be done and this judges way is only one and among the most absurd and foolish. The approach mush be a philosophically principled, logically coherent legal basis that does not arbitrarily allow the courts to pick and choose who can detain this chimps and for what purpose.
A writ of habeas corpus cannot be applied to non-persons. The law specifies and clearly intends it to only apply to persons (and to human persons). The judge must declare these chimps legal "persons" at minimum, and arguably must declare them human persons, otherwise she is blatantly misapplying the clear intent of the existing law. Anything the Non-human rights groups claims to the contrary is dishonest bullshit on their part.
Note the following:
The writ [of habeas corpus] requires Stony Brook University, represented by the Attorney General of New York, to appear in court and provide a legally sufficient reason for detaining Hercules and Leo.
Guess what? Unless the chimps are just allowed to walk out the court doors (or just hang out if they want), then they will only leave the court under detention and be brought to a place against their will where they are detained against their will. IOW, it is philosophically, scientifically, and legally absurd to claim that their "person" rights are violated any more by Stony Brook detaining them than by anyone detaining them. In fact, it is highly likely the chimps are attached to their handlers and would prefer to stay with them than go with strangers. Thus, any removal of them from Stony Brook custody would objectively be an even greater violation of their will and thus their presumed "rights". "Detention" against their will can have nothing to do with the basis for why they are removed from Stony Brook, because their is no principled or legal basis on which to do it.
It must be based upon the manner in which they are treated their, and a principled scientific basis for assuming beyond reasonable doubt that they would prefer to be elsewhere. Stony Brook are their current caretakers and thus guardians if they are to be thought "persons". Thus, their removal would be akin to removal of a child from their parents. The State needs to prove abuse warranting removal. Children are allowed to be detained against their will by their guardians. They are not allowed to just roam the streets. If granted the person status similar to children, then at least it would make sense to keep "detaining" them but change who and how they are detained. But doing that still requires a change to existing law to allow for non-human persons to be covered by laws that refer to persons, and it must specify which non-human are and which are not covered. Also, once done then the chimps would have all the rights of non-adult humans, and criminal laws would also apply to them and their guardians for any of their actions.
Far more sensible would be the creation of new laws that apply specifically to chimps and any other non-humans we want to grant special protections to and enumerate what those protections are. Then nothing in current law in reference to "persons" would apply to them, which is far better for the integrity of the law than courts arbitrarily deciding which do and which not apply, even though the sole basis for apply any is that they are now "persons".