In civil law jurisdictions, such contracts are invariably never enforceable, because this contradicts the public policy principle (lit. "public order and good morals"), one of the basic principles of the civil law of continental jurisdictions, cf. e.g., Article 6 of the French Civil Code, Art. 138 of the German Civil Code, and Art. 90 of the Civil Code of Japan.
Personal freedom could not be deprived without due process and according to law; moreover, it is a crime to do so in almost any jurisdiction. If such a contract would be allowed, then it would be a major breach of public order (and the law). Therefore, it is imperative that such contracts could not be allowed.
If a contract breaches the law and the public order, then it is deemed void. It is not only unenforceable, but also considered to be technically non-existent. If one party has already been imprisoned, they are entitled to damages due to tort/delict, since the contract was void and the captor had no valid reason to imprison. (Of course, the imprisoning party will likely also be prosecuted.)
In some civil law jurisdictions, a legal act void in part is considered void in its entirety. (By jurisprudence constante in some jurisdictions, but also codified in some jurisdictions, cf. Art. 139 of the German Civil Code). However, in other jurisdictions, a legal act that is void in part is only partially void (cf. Art. 156 of the Civil Code of the People's Republic of China). But regardless, it is highly likely that a contract with such outrageous terms would be considered to be negotiated in ill faith, thus rendering the entire contract void.
So, in conclusion, the said articles in the contract is not enforceable, fully null and void, and very likely the entire contract is also null and void.