How are Mary Dempster and Dunstan's mother foils of each other?
Characters who are foils of each other are usually similar in some ways, but not in others. The importance is in the contrast between them, which should serve to illuminate something in one or both of the characters, or possibly in the overall plot. Mary Dempster was, in many ways, the converse of Mrs. Ramsay. In everything that Mrs. Ramsay was competent (such as housekeeping, running a family, having a good reputation in town and in church) Mary was incompetent. While Mary Dempster, after being hit with a snowball and delivering her premature baby Paul, becomes a failure in every way that the town of Deptford recognizes a that a wife and mother could possibly fail, culminating in her spectacular fall from grace (because of her tryst with the tramp in the gravel pit) and her descent into madness, Mrs. Ramsay remains the steadfast, perfect mother and wife. That Mrs. Ramsay is as charitable to Mrs. Dempster as she can possibly be doesn't change the fact that Mrs. Ramsay is the example of what the world considers successful (for women of her time and situation, at least,) while Mrs. Dempster was an example of everything that could go horribly wrong.
But Mary Dempster's saintly qualities were recognized early by the young Dunstan (then Dunstable), and he similarly recognized (or imagined) the lack of those miraculous spiritual qualities in his own mother. It is not that Mrs. Ramsay was cruel or unkind -- she was a good, caring woman -- but Dunstan felt more smothered than loved by her. There were some epic battles between Dunstan and his mother, and eventually Dunstan only felt a desire to be independent from her. Mary Dempster, on the other hand, made no demands on Dustan, and he, in many ways, felt more at home with her, even in her madness, than he did with his own mother.
The scene where Dunstan's mother became uncontrollably angry with Dunstan, a few years after Mary Dempster's breakdown, caused Dunstan to react very unfavorably toward her. It was as if he would allow such weakness in Mary Dempster, but it was intolerable in his own mother. By the same token, Dunstan attributed miracles to Mary Dempster (such as the supposed raising of Dunstan's brother from the dead) that he would never imagine his mother being capable of. Dunstan was not able to conceive of his pedantic, Calvinist mother having a spiritual dimension, perhaps because she was so competent in the practical realm. By comparison Mary Dempster had no competence in the practical, material world; so she assumed mythic and saintly proportions in the spiritual realm, at least in Dunstan's mind.