> society was much less religious overall and there was less reason to keep homosexuality illegal.
I'm not actually sure it was an entirely religious thing. It seems like it was an amendment tacked onto a bill that would protect girls from sexual exploitation by this guy: https://en.wikipedia.org/wiki/Henry_Labouch%C3%A8re
I am not really well-versed in British legal history. I was under the impression that the original Buggery Act was motivated religiously, and that Wilde was prosecuted under that Act (maybe amended).