well, it’s not the church in that case I think. Rather it’s the pastor/priest.
They have a role of authority over others and that role, wherever it shows up in society, carries with it some societal responsibilities.
That’s regardless of government or laws; it’s just how it is; if you’re over others, you carry some responsibility for them. at least I think of it as a natural law.
But some states see the confession seal as sacred and not to be messed with.