Indeed, if a defendant is found at trial not guilty of serious crime due to mental illness, just like not guilty due to insanity, the defendant is not then automatically released.
If someone commits a heinous act and is considered by a court of law to not be responsible for their actions due to mental illness (or legal insanity) then the court mindset is that society still needs to be protected from them. Moreso given that they have already committed this terrible thing due to their affliction, then there is a very good chance they may do so again.
The defendant is then locked away in an insane asylum, or some kind of mental hospital, for as long as they are deemed dangerous to society. That is, until they are cured. No set time is given, and the defendant will remain "locked up" until a professional-mental-health-body has deemed that the defendant will never commit such a violent action again. Then this body will need to petition the courts, and convince the courts of such, before the defendant is released back into the world.
It is well document that defendants who have been found not guilty due to insanity/metal illness, have actually sent more time in a mental-illness facility than other defendant found guilty of the same crime actually spent in prison.
"Not guilty due to mental illness" does not equal "innocent"
Indeed, the defendant in this case, if he had actually been found not guilty due to mental illness (not stating what the actual verdict was in this episode, not to spoil it), and by some unlikely chance was then free to just go home, the next morning, CPS would be at his door to take away his children from such a potentially dangerous household.
Pleading, "I did the dreadful thing I am accused of, but I was not responsible as I was not aware of my actions, due to mental illness" can garner a worse end result than just pleading guilty, as no court will allow an otherwise murderer back into society just because he was found not guilty due to mental illness.