The answer to your question can be found in chapter V, titled "Hester at Her Needle".
Hester Prynne certainly could have avoided a lot of problems by simply leaving the village. However, as Hawthorne writes:
Her sin, her ignominy, were the roots which she had struck into the soil.
What these words entail is that her actions, and the consequences of them, have changed Hester so tremendously that she basically was reborn again into another woman. Although this woman has less than an ideal life, it is life nevertheless and Hester felt a moral responsibility to embrace it and live with it. Therefore, that first reason can be attributed to moral responsibility to abide by whatever comes her way.
The second reason is Dimmesdale.
another feeling kept her within the scene [...] one with whom she deemed herself connected in a union, that, unrecognized on earth, would bring them together before the bar of final judgment...
Even after the humiliation, the loneliness, and the terrible treatment that Hester has endured from the villagers and the aldermen alike, the fact remains that Hester not only feels love for Dimmesdale, but also a spiritual connection that keeps her bound to him. It is almost unbelievable to the modern reader that Hester would harbor any love inside of her for the man that has left her to suffer in silence for actions committed by the two of them. Moreover, that this man is faking his righteousness and still acts like a man of God makes her connection to him all the more awkward. However, those are exactly the reasons why Hester decides to continue a sad life in the village facing society head on.
There are two reasons that Hawthorne gives for Hester's decision to remain in Boston: 1.) This was the "spot where some great and marked event" gave "color" to her "lifetime." The most significant events in her life occurred in Boston, and, as Hawthorne says, "The chain that bound her here was of iron links." 2.) In Boston, her lover and father to Pearl remained. Bound to him by what she considered to be an unbreakable union, Hester could not leave him.
Hester says that she must work out her penance in Boston since it was the place where she had sinned. Hawthorne says her reason is a "half-truth" because her desire to remain close to Dimmesdale was foremost in her mind.
For one, she has nowhere else to go. Two, she believes that running would only convince the people further of her guilt, which she does not believe.
Later in the novel, her "A" comes to mean more than "adultery"; she proves herself an "able" and productive member of the colony; an "asset" rather than an embarrassment.
It is true that Hester will not leave the colony because she loves her fellow sinner, Pearl's father. Furthermore, his gaze seems to provide her with the only relief she can ever feel. The narrator says that she sometimes "felt an eye -- a human eye -- upon the ignominious brand, that seemed to give a momentary relief, as if half of her agony were shared." Thus, Hester's only opportunity to experience any relief from the shame of the scarlet letter is when her co-sinner looks upon it.
Moreover, Boston "had been the scene of her guilt, and here should be the scene of her earthly punishment; and so, perchance, the torture of her daily shame would at length purge her soul, and work out another purity than that which she had lost; more saint-like, because the result of martyrdom." Hester seems to accept the Puritans' idea that she has committed a sin for which she must atone. She feels that she ought to remain in Boston and endure the punishment that is designed to offer her a chance to repent of her sin; if she were to leave, it would be as though she is escaping this opportunity. Furthermore, the fact that she chooses to stay, instead of running away, she hopes, will carry her a long way to achieving such atonement.