The difference is was the law immoral and now we are fixing that error, or did the law have good intent but now the politicians think that there is a better way to reach the solution. For example, if alcohol was taxed at 30% but someone only paid 20% tax, they would be jailed. If the tax got changed to 20% the person shouldn't be released because they broke a moral law. In your example of gay men being jailed, that law is immoral and therefore those people should be release after removing the law.
I don't think that jailing people who were consuming illegal drugs is an immoral law. Sure, the law may not be so good and should be changed. But, people who break moral laws are not good for our society.