Because there is no law against it?
that's the same reason I can paint my house lime green. Laws are generally restrictive, not permissive. That means, they limit actions so, if there is no law restricting an action, it is generally considered to be legal.
I would think a person could make a reasonable argument that since they were not found guilty, there is no justification to charge them for their stay. Basically, since it wasn't proven you should have been jailed, they have no right to charge you. I do not know if that would win a case or not since the police have to have probable cause to make an arrest. That may be enough to allow the sheriff to charge for your stay.