When one is a risk of harming others due to mental illness, there is absolutely no justification for not taking preemptive action when lives are at stake. One needs only to read about massacres inflicted at the hands of Elliot Rodger (Santa Cruz Isla Vista killings), Adam Lanza (Sandy Hook Elementary School shooting), Jared Loughner (Tucson, Arizona shooting), and Seung-Hui Cho (Virginia Tech massacre) to understand that it is foolhardy to give severely disturbed individuals the option to not take the treatment they desperately need. When a continuous pattern of aggressive behavior arises, action must be taken immediately regardless of the mentally ill's consent if innocent lives are to be protected.
It is a hard question because the mentally ill is not really in a place to always know what is or is not best for them. In the end though it is kind of like would you not help a sick child because they refused the medicine when it tastes bad? We should treat them to help them as long as the treatment is not harmful.
Forced treatment of the mentally ill is aimed toward helping them. One of the most difficult aspects of mental illness is that sometimes the individual affected is not able to recognize that they need help themselves. They need help and a push to get help they need to be able to function at their full potential. With that being said, many of the medicines for mental illnesses are very dangerous and can have negative side effects: those should only be prescribed under good supervision of doctors.
I believe in a rehabilitative and incapacitative model of justice. But that being said people who are a danger to others should just be sentenced under the appropriate law and offered parole as appropriate. Some people may be able to get out in a few days or a few weeks for instance people acting out temporarily for some reason (example: drugs) and then stabilized. The law should allow for and even require in some cases sentences that include stipulations that observations shall be made to determine the length of the sentence during the person's sentence. Treatment should be offered but not required. If you want to just stay in jail where you can't hurt anybody that should be your right.
We live in a material world so distinguishing between "mental institution" and "jail" is meaningless. Every behavior and thought is based on chemistry (Though I'm not saying that means drugs is always the solution, a corollary of this fact is that every treatment that effects a person's behavior or thoughts in some way is a chemical treatment and indeed studies show chemical changes in the brain when people merely talk to each other.)
We don't have to call it "mental illness" we can call it what it is "criminal behavior". It is necessary for society to regulate behavior somewhat to protect its members but we need to do this openly and acknowledge it rather than using the euphemism of "mental illness" as that euphemism distorts our reasoning on it putting people with strange ideas who aren't hurting anyone at risk of oppression. Runaway slaves were once diagnosed with drapetomania. Anticommunists in the Soviet Union were diagnosed with "sluggishly progressing schizophrenia". Homosexuality was once considered a mental disorder.
Cases where people aren't being threatened such as depression should simply fall under the umbrella of subjective distress. It's absurd to say someone is depressed if they are content with their life as it is. But if someone has subjective distress then doctors should be able to within reason treat that. We do not need to call it mental illness in order to do that.
Conditions that change the way children learn should be typified and adjustments made accordingly but calling it "illness" risks the possibility of eugenic genetic engineering destroying human mental diversity. That would mean no more Einsteins, no more da Vincis, no more of a great deal of genius and innovation. Worse it could turn into a vicious cycle where the first round of 'abnormals' are 'cured' and then we compare ourselves and identify the next 'abnormals' and we become more and more uniform and in the process blind to the progress innovation and beauty that we have lost.
I wouldn't call this model an absolute to be followed. I think if someone has Alzheimer's, we have a cure and they don't want it then it should still be administered. But that's an extreme case.