Obedience to a judgment for the discharge of a person imprisoned or restrained, pursuant to the provisions of this chapter, may be enforced by the court by proceedings for a contempt. A peace officer or other person is not liable to an action or proceeding for obeying the judgment of discharge.