Keeping public safe and rehabilitation. Jail is not just punishment.
And if you charged for courses you would have a lower rehabilitation level and is pretty pointless anyway.
Lower education is free. They are in prison unable to earn money. Charging them achieves little and lessens the chance of successful education. .
The cost of the courses to end users is generally free anyway (college level stuff) and would easily be recouped through the effects of lower rates of re-offending.