Pope Benedict XVI has condemned British equality legislation for running contrary to "natural law" as he confirmed his first visit to the UK later this year.

In a letter addressed to the Catholic bishops of England and Wales, the pope praised Britain's "firm commitment to equality of opportunity for all".

However, he criticised UK legislation for creating "limitations on the freedom of religious communities to act in accordance with their beliefs". It is thought his comments relate to laws that came in last year preventing adoption agencies from discriminating against gay couples and also Harriet Harman's equality bill, currently going through parliament.

The pope, whose visit is expected in September, made the comments after hearing representations from English and Welsh bishops on their concerns about the place of religion in an increasingly secular society.

They told him sexual orientation legislation that came into effect on 1 January 2009 had forced the closure of half the Roman Catholic adoption agencies because the law making it illegal to discriminate against gay applicants went against their beliefs.

In his letter the pope said: "The effect of some of the legislation designed to achieve this goal has been to impose unjust limitations on the freedom of religious communities to act in accordance with their beliefs. In some respects it actually violates the natural law upon which the equality of all human beings is grounded and by which it is guaranteed."

It is also thought the pope was referring to the equality bill, which narrows the special exemption enjoyed by churches allowing them to exclude people whose lifestyles do not fit in with the religious ethos of an organisation when hiring staff. The bishops cited it as another restriction of their freedom of religious belief.

The archbishop of Westminster, the Most Rev Vincent Nichols, who is in Rome, said: "It has been clear that he knows the situation and applied it to a move in legislation to look for equality."

The pope urged the bishops to make their voices heard and to defend the faith, saying Christian teaching did not undermine or restrict the freedom of others.

His remarks drew swift criticism from the National Secular Society, which said it would stage protests during the visit.

Terry Sanderson, the society's president, said: "The taxpayer is going to be faced with a bill for £20m for the visit – in which he has indicated he will attack equal rights and promote discrimination."