Fundamentally, the state is attempting to temporarily withdraw from society those persons whose mental state is such that their presence may pose a danger to society or to themselves.
The state is providing treatment to those individuals who may not otherwise have the wisdom or the wherewithal to seek it themselves.