An Alabama pastor whose residential ministry for sex offenders was shut down by a new law, has been allowed by a federal judge to proceed with his religious liberty lawsuit against the state.

Pastor Ricky Martin of the Triumph church in rural Clanton says Alabama targeted his ministry when it passed a law that only applied to one county, and only shut down his program.

“We was trying our best to provide the housing for them,” said Martin. “They was going to church, they was serving the lord, they had been saved, of course.”

Alabama has some of the most restrictive laws in the nation that govern where sex offenders can live. The state requires offenders to have an approved address before they can leave prison. Sex offenders in Alabama are also prohibited from living within 2,000 feet from any school, college or daycare. If an offender does not supply law enforcement with an approved address by the time he or she is eligible for release, the offender is remanded to the custody of the local sheriff. The law has no exception for mental illness or disability.

Martin said he ministered to sex offenders in prison, and began the transitional housing program behind his church after many men were unable to leave jail when their sentences were completed.

The pastor had five trailers set up behind the church, about 300ft from each other, and that, at most, he had about a dozen men living in the trailers at any one time. Just 8,700 residents live in Clanton, a town smack in the middle of the state between Montgomery and Birmingham on Interstate 65.

To live in the small ministry, the men had to sign an agreement prohibiting “tobacco use, fighting, possession of weapons and pornography and use of foul language”.

Martin said the men were not charged rent unless they were working, and that the church worked to get the men jobs and government assistance. “We tried to get them signed up for food stamps to where they could at least feed themselves, and we also required them to go to church,” said Martin.

But in 2014, after the trailers had been set up for a couple of years, a then Alabama house representative Kurt Wallace, a Republican from nearby Maplesville, took issue with the ministry.

“The big difference is in congregating,” said Wallace. “You put 26 drug addicts together, what are they going to talk about? Addiction. I mean, it’s just common sense.”

Wallace said he believes it is harmful for sex offenders to live together, at least in his county, despite acknowledging that hotels in Birmingham and Montgomery house as many as “30 or 40 of them living right next to each other”.

In a letter to Martin at the time the bill was being debated in the house, Wallace told the pastor and his wife that the ministry would lead to “smarter criminals”, because “more often than not … they share ways they were able to do what they did and how and why they got caught”.

He said he passed the law only for Chilton County because law enforcement in other counties opposed the bill, telling Wallace it was easier for officers to check up on sex offenders if they all lived in one location.

“You scatter [sex offenders] out, you cause [sheriff’s deputies] a bunch of hassle,” said Wallace.

According to the lawsuit, Martin was told by the prosecutor he would be charged under the law if he did not evict the men. Facing what he believed would be up to $60,000 in fines, he shut down the small ministry.

While Wallace was in the Alabama house, he was cited as one of the seven most conservative members by local political website Yellow Hammer News. He described himself as a “conservative Christian who will fearlessly defend my God, country and family against all who would do them harm”.

The federal judge in the case, citing precedent, described Alabama’s sex offender laws as “comprehensive” and “debilitating”. The climate in Alabama is so restrictive, one legislator in Alabama’s legislature proposed forcing sex offenders to pay for their own chemical castration before they can leave prison.

The judge’s ruling allows the case to move forward in federal court. Martin’s attorneys, with the Alabama chapter of the American Civil Liberties Union, decided against bringing a case under the state’s religious freedom laws citing uncertainty – no case has ever been litigated under the state’s law.

Martin described his church, which still ministers to sex offenders who no longer live there, as “preaching and teaching Jesus, teaching them things concerning God’s word”. He said, “I believe if a person’s right with God, and they’re staying in right fellowship with God, they’re so much less likely to return to a life of crime.”