It varies by state, but I just looked up New York, California, and Texas and they are surprisingly uniform. Getting a 72-hour hold is pretty easy, and a psychiatrist can tell the court if s/he deems it necessary to hold for an additional 14 days (ostensibly, so they can verify that whatever medication they choose to administer has taken effect). These courts are pretty much set up to rubber stamp whatever the psychiatrist wants to do; many hospitals that have psychiatric services have these courts in the same facility. After that, although the patient has the right to leave the hospital whenever they want, but in many cases they aren't told that, or that they may need to call a lawyer to take them court in order for the judge to issue a release.