Meaning to die or not do well at all. Stems from the fact that when someone dies or is very sick they will lose rectal sphincter tone and quite literally shit, on the bed.
My truck was working fine yesterday but it shit the bed last night.
Shit the bed is when someone freaks out about something and can't handle it. When you get really mad and are inconsolable. When you get really upset.
Mike shit the bed when he found out his girlfriend was cheating on him. Bob shit the bed when he saw his test score. Sally shit the bed when she didn't get a promotion.