In The Outsiders, Dally robs the grocery store because Johnny’s death leaves him desperate, self-destructive, and ready to die.
Johnny is the person Dally cares about most. Earlier, Dally tries to stop Johnny from turning himself in because he fears jail will harden Johnny the way it hardened him. He wants Johnny to keep the innocence and goodness Dally feels he has lost. When Johnny dies after the rumble, even the greasers’ victory cannot comfort him. Dally rushes to the hospital to tell Johnny they won, but Johnny answers, "Useless fighting's no good." Then Johnny’s last words to Ponyboy are "Stay gold, Ponyboy. Stay gold." Dally runs from the hospital in grief.
The robbery is part of Dally’s breakdown. Afterward, he calls Darry and says he has robbed a grocery store and is running from the police. The greasers hurry to help him, but when they reach the vacant lot, the police arrive too. Dally pulls out the gun his friends know is unloaded, using it in a way that makes the police think he is armed. They shoot him. Ponyboy understands what Dally is doing: "Dally Winston wanted to be dead and he always got what he wanted."
So, Dally robs the store because he wants to die after losing the one person who gave his life meaning. The act fits the violent, desperate identity the outside world already expects from him, while Ponyboy remembers the loyal Dally who helped Johnny and Ponyboy escape, saved Johnny from the burning church, and tried to protect Johnny from becoming like him.