Technically, the police have 23 days to charge someone before they must be released. In serious crimes, police can (and likely will) re-arrest the person on a different charge.
I very much doubt that the police have held someone for months for stealing a dumpling, though.
In addition, for everyone mentioning the 99% conviction rate, it's important to keep the other part of that in mind as well: Japanese prosecutors typically drop ~50% of cases.