It happened when Sonic refused Sally's request to stay at the castle with her, but the root cause was the severe psychological trauma Sally suffered after believing Sonic was dead for a YEAR! She didn't know if he was even alive, and when he comes back? He says that he'd willingly give his life away to save people. Of course he's a hero and that's what heroes do β they selflessly give everything for the sake of salvation, but Sally didn't need a hero, she needed Sonic (preferably alive eh). It's that he says it in a way that tells Sally his life is cheap and expendable for the cause. The slap reads as the moment the trauma overrides her composure, not some tantrum.
Before you go throwing trash on a character over a complex moment β learn the context!