Section 22. If the prisoner is lawfully imprisoned or restrained and is not entitled to be admitted to bail, he shall be remanded to the person from whose custody he was taken or any other person or officer authorized by law to detain him.