In any judicial proceeding for involuntary commitment or detention except under RCW
71.05.201, or in any proceeding challenging involuntary commitment or detention, the prosecuting attorney for the county in which the proceeding was initiated shall represent the individuals or agencies petitioning for commitment or detention and shall defend all challenges to such commitment or detention, except that the attorney general shall represent and provide legal services and advice to state hospitals or institutions with regard to all provisions of and proceedings under this chapter other than proceedings initiated by such hospitals and institutions seeking fourteen day detention.