In The Scarlet Letter, how does the setting contribute to the overall theme of the book?
There are many aspects of the setting that can be analysed as part of answering this question. One of the most significant parts of the setting is arguably the location of Hester's abode where she chooses to live and raise Pearl after the end of her imprisonment. Note how this setting is described in Chapter 5:
On the outskirts of town, wihin the verge of the peninsula, but not in close vicinity to any other habitation, there was a small thatched cottage. It had been built by an earlier settler, and abandoned because the soil about it was too sterile for cultivation, while its comparative remoteness put it out of the sphere of that social activity which had already marked the habits of the emigrants.
This setting is immensely significant and clearly contributes to the theme of isolation and alienation. Hester Prynne, in choosing to remain in the same town where her "crime" was identified and also punished, is physically and psychologically placing herself on the fringes of respectable society. Consider how this impression is conveyed through phrases such as "comparative remoteness" and also the soil being "too sterile for cultivation" reinforce this impression. Hester is left to eke out her existence in a place that has been rejected by others, and the unfertile soil becomes a symbol of how difficult that task becomes as she continues to face the censure and disapproval of those around her.