TBH, while he did break the law, I think his course of action against the state was justified. That's obviously not an excuse that will fly in court, but saying "he deserved to go to jail" is a bit disingenuous given the context.
Mandela pleaded guilty to the charges against him (sabotage of various state and military instruments). The state was looking for evidence of him having a hand in killing/hurting civilians because they wanted to hang him. They couldn't find any, so they settled on life imprisonment.