Time spent in custody pursuant to orders issued under Section 104-17 or 104-20 or pursuant to a commitment to the Department of Human Services following a finding of unfitness or incompetency under prior law, shall be credited against any sentence imposed on the defendant in the pending criminal case or in any other case arising out of the same conduct.
725 ILCS 5/104-24