The purpose of Mary's visit to the grocery store and conversation with Sam is to establish a credible alibi for herself.
Within the previous hour, Mary's husband told Mary that he was leaving her. Shortly after, Mary clubbed him to death with a frozen leg of lamb. The text says that she is ready and willing to take the punishment for herself, but Mary is not willing to risk her unborn child.
As the wife of a detective, she knew quite well what the penalty would be. That was fine. It made no difference to her. In fact, it would be a relief. On the other hand, what about the child? What were the laws about murderers with unborn children? Did they kill then both-mother and child? Or did they wait until the tenth month? What did they do?
Mary Maloney didn’t know. And she certainly wasn’t prepared to take a chance.
In order to protect her child, Mary decides that she needs to cover up her involvement with Patrick's death. That means two main things. First, she needs to get rid of the murder weapon. She does this by cooking it. Second, she needs to not be home when Patrick was killed. By going to the grocery store, Mary can claim that she wasn't home when Patrick was killed. Talking to Sam guarantees that somebody else can vouch for the fact that Mary was indeed at the grocery store between time "A" and time "B."
Mary's plan works. The detectives show up to her house. They begin asking her all kinds of questions, and Mary explains that she had to go out to the grocery store after Patrick got home in order to get the rest of the dinner supplies. The officers immediately check up on Mary's story. They contact Sam, and he corroborates everything that Mary stated.
She told her story again, this time right from the beginning, when Patrick had come in, and she was sewing, and he was tired, so tired he hadn’t wanted to go out for supper. She told how she’d put the meat in the oven – “it’s there now, cooking” – and how she’d slipped out to the grocer for vegetables, and come back to find him lying on the floor.
"Which grocer?” one of the detectives asked.
She told him, and he turned and whispered something to the other detective who immediately went outside into the street.
In fifteen minutes he was back with a page of notes, and there was more whispering, and through her sobbing she heard a few of the whispered phrases – “...acted quite normal...very cheerful...wanted to give him a good supper… peas... cheesecake... impossible that she...”