Answer:
Some defendants are insane and putting them in prison is not the solution. When these defendants are put into mental institutions they are released when they are determined to be sane. Sometimes this can be longer than their maximum prison sentence if they were found to be guilty.