A lot of people are talking about alternatives to cash bail recently, which made me wonder, why does pre-trial detention exist in the first place?
My layman's understanding of pre-trial detention is that it's a kind of "buffer" or a necessary evil. The root problem appears to me that we don't have enough judges, public defenders, etc. to get everyone to trial immediately, so we have to hang onto them until a slot opens up. Bail exists because of flight risk, so if in some world there were no need for pre-trial detention, we wouldn't need bail or any alternative.
Is my understanding essentially correct? In other words, does pre-trial detention exist because of a resources constraint? Or is there some more fundamental reason why we have this intermediary step between arrest and trial?
My question is coming from a US-based context, hence my lead-in about "cash bail". However, I'm curious about pre-trial detention in general, regardless of whether bail is used or what form it takes.