When it's illegal to ‘first do no harm’

Why do involuntary psychiatric commitment laws regularly make doctors break their Hippocratic Oath? And what could we do instead?