Although it seems like the judge has the ultimate decision in sentencing a person to prison time it's ultimately up the state and what laws they have.
Some states have minimum prison sentences or jail sentences that the judge must impose on someone committing a certain crime.
Take murder for example. In that case if the person is convicted and found guilty then the judge must either decide on a death penalty sentence if the state has that or decide on a life sentence.
Or a life sentence with a possibility of parole such as after 22 years. The person must serve the 22 years before coming up for parole and even then if they are sentenced to life with possibility of parole they are not guaranteed to get paroled and could actually have to stay in prison their whole life and never leave the prison again unless in a body bag.