In The Scarlet Letter, Hester Prynne chooses to stay in Boston out of attachment to the life-changing events that had happened there and to the person involved in them--the man who desecrated her marriage but was not punished with adultery charges.
The narrator describes this decision as "marvelous" in that there was absolutely no laws or stipulations of her punishment that forced her to remain there; it was completely a matter of free will. Hester has every opportunity to leave and is,
"free to return to her birthplace, or to any other European land, and there hide her character and identity under a new exterior, as completely as if emerging into another state of being."
Despite this, she does not run from her sin or from her identity; her sin, in fact, seems to give her "a new birth" which commits the land to her as a "life-long home."
Meanwhile, she sees the man she cheated with as being connected to her in
"a union, that, unrecognized on earth, would bring them together before the bar of final judgement, and make that their marriage-alter."
The narrator describes this motive--Hester's desire to be weighed and judged by God with this "tempter of souls"--as "half a truth, and half a self-delusion."
Overall, Hester decides that the place where she committed her greatest sin must be the place where she carries out her "earthly punishment." Therefore, she settles into "a small thatched cottage" and prepares to endure a great deal of ostracism from the community.