Just to add a bit, Hawthorne is commenting on the impossibility of having a Utopian community(in chapter one) which was a popular idea with some of his contemporaries (such as Emerson). Hawthorne attempted to live in a Utopian community and it failed miserably, costing him a lot of money. In chapter one, he points out that a Utopia is impossible, because you can't stop people from dying (hence the need for a cemetery), and you can't stop people from commiting crimes (hence the need for a prison).
I'm not sure if this is what you're referring to, but in Chapter One, the town is said to have put land away for a cemetery and a prison. Chapter Two is where Hester walks out of prison to stand on the platform with all of the village watching her.