Minn. Stat. § 611.51
If the defendant is convicted, any time spent confined in a secured setting while being assessed and restored to competency must be credited as time served.