How do you do it? By setting rules and enforcing boundaries.
Yes, he will be upset and have a meltdown. That's good. That's what should happen so that he realises there are consequences to his actions. It has to matter to him.
He was giggling because it was all a game. In the past, nothing upsetting has happened to him because of his behaviour. Now you are enforcing the boundaries, he will learn. And if he is clever he will learn fast. But it is imperative that you stand firm, otherwise all you will teach him is that if he pushes hard enough, the boundary will break.
I waited for all the sobbing to subside, then we had a cuddle and I explained to him that if I didn't help him realise why throwing food is not acceptable then he might do it at school, or at a friend's house, and got him to tell me how he thought teachers/other parents would react in that situation
This bit is where you feel guilty. Don't. You are giving him the tools to deal with life. You are making him feel safe by enforcing the boundaries.
I always think of it like this. When we get on a rollercoaster the first thing we do is push the bar in front of us. We want to know that it will hold. We want to be safe whilst we have fun. If the bar gave way, or only held fast some of the time, we wouldn't ride the rollercoaster. We have to trust the bar. He needs to trust you, as his parent, to make the right decisions for him.
Children who cannot rely on their parents, learn to rely on themselves. They can become quite disruptive with their behaviour and refuse to follow direction from adults. Your ds isn't there yet but he could be if you don't nip this in the bud.
So don't bother with the cuddle and don't give lots of attention for tears. Just continue in a matter of fact manner, as if you expect his behaviour to change. He doesn't need to know the ins and out of why you shouldn't throw food. He already knows it's naughty. He just needs to learn that these are the mealtime rules and it's up to him to choose how to behave and face the consequences, good or bad.
And when he behaves well give him lots of praise. I used to take my ds out for a meal (beans on toast at the local cafe) to practise eating out. He would sit nicely waiting for his food, have a quiet chat, use a napkin, eat carefully with a knife and fork, wait for others to finish, say thank you to the staff and walk out nicely
. He was only about 3 when we started but he thought it was a great treat and I could praise him on his lovely table manners.
Well done for seeing it through. It's not easy, I know, but it will get easier the more you do it. And you will be so glad you did when he becomes a teenager and knows that you mean what you say. Good luck.