If determined necessary the Psychiatric hospital can legally hold you against your will for up to 72 hours and then if safe to do so then they must let you go unless they have a court order to hold you against your will for your safety and other peoples safety.
If the Psychiatric Hospital has a court order to hold you then they can hold you for up to 90 days and if needed they can get a court order to hold you against your will much longer.
If they haven't gotten a court order to hold you longer then they must release you from the Psychiatric Hospital within 72 hours.