It's intelligible, but "stay" doesn't have a very strong sense of being obliged to remain, so I think this is better: What's the longest you can be held in custody? I don't think "for" on the end is really necessary.
New words, one handy idiom, and a 2-minute quiz — delivered to your inbox to keep your streak alive.