The only way the court keeps bail is if you fail to appear for your hearings. If you did, and they issued a warrant, the bail can be forfeited. If you did make your hearings the bail should be exonerated, which means given back to you, at your final court appearance. If you had an attorney on your previous matter, you can ask them to contact the court to get your bail back.
As for pain and suffering/lost wages, it's unlikely you have a claim. The criminal process in general gives a lot of immunity for civil claims against prosecutors and judges if their actions are made in good faith. If the law they were working under was valid at the time of your arrest, it's almost per se good faith, i.e. they are immune from suit. There must be a serious abuse of process to even get a suit in the door, and even then it's unlikely you'd win. Further, "fear of jail" is kind of the point; the courts want people afraid of jail so they won't commit future crimes and so they abide by court orders.
In short based on what you've written here, while you should be able to get back your bail money if did all the requirements, it's unlikely you'll have a suit for extra damages. But, an attorney you hire who can look at all the paperwork may come to a different conclusion. Good luck.
Noah is correct. If you posted bail and then showed up for all of your court dates and abided by all of the conditions of your release, then the bail amount should have been given back to you at the conclusion of your case. If you did not follow all of the conditions of your release during the case, then the bail is forfeited, even if the charge was based on a law subsequently found to be unconstitutional.
As far as a lawsuit against the city/state, it is very likely that you have no legal recourse. If the prosecutor was proceeding against you based on a law believed to be valid, then the city/state did nothing wrong. Even in cases where due process rights are violated (too much time spent in jail, charges not brought on time, etc.) it is still extremely hard to successfully bring a lawsuit.