This is the kind of error that might be brought through a habeas corpus writ. Lots of added details are needed and no one online can know what is going on in your case because online we cannot find out any of those details. You need a lawyer. Check with a lawyer in your locale to discuss more of the details. A habeas corpus writ is an action through which a person can seek relief from the unlawful detention of him or herself.
Good luck to you.
NOTE: This answer is made available by the out-of-state lawyer for educational purposes only. By using or participating in this site you understand that there is no attorney client privilege between you and the attorney responding. This site should not be used as a substitute for competent legal advice from a licensed professional attorney that practices in the subject practice discipline and with whom you have an attorney client relationship along with all the privileges that relationship provides. The law changes frequently and varies from jurisdiction to jurisdiction. The information and materials provided are general in nature, and may not apply to a specific factual or legal circumstance described in the question.