If a person has been committed, detained, imprisoned, or restrained of liberty, under any color or pretense whatever, civil or criminal, and if upon application made in good faith to the court or judge thereof, having jurisdiction, for a writ of habeas corpus, it is satisfactorily shown that the person is without means to prosecute the proceeding, the court or judge shall, if the judge finds that such appointment is necessary to ensure a full, fair, and impartial proceeding, appoint counsel for the indigent person pursuant to chapter 23A-40. Such counsel fees or expenses shall be a charge against and be paid by the county from which the person was committed, or for which the person is held as determined by the court. Payment of all such fees or expenses shall be made only upon written order of the court or judge issuing the writ. The ineffectiveness or incompetence of counsel, whether retained or appointed, during any collateral post-conviction proceeding is not grounds for relief under this chapter.
SDCL 21-27-4