5 year old son self talk

I’ve had two instances in the last few months when my 5 year old son has come out with some heartbreakingly negative self talk. I know we all naturally do this but I can’t believe what’s happening. He’s sensitive so that might be it but we avoid negative self talk in front of him so I’m shocked this is happening.

We talk a lot about feelings I tell him to be his own best friend and how he talks or thinks about himself is really important.

It happens when he realises he’s done something wrong that we will tell him off and feels I assume shame.

The first incident he left the house looking for me without telling my husband. My husband heard him shouting in the street and went to get him. My husband told him he must never leave the house on his own. When I got home my son burst into floods of tears and told me he was the stupidest boy in the entire world over and over.

Last night my husband put the ipad next to my sons bed so he could watch it when he first woke up. This was the first time this had happened. At 9pm we heard steps on the stairs and the Ipad playing a TV episode. I reacted and said you’re not watching TV are you? My son must have felt he’d done something wrong he went back to his bed sobing with tears and said over and over I’m nothing, I’m nothing, I’m nothing.
I told him he was everything and laughed that he had been watching TV. I said I wasn’t mad and it was mummy and daddy fault. I told him I will always love him no matter what he does.

Thanks for any insight.