It is rude, in any social setting, including family settings, and whether it includes children or not, to eat or drink without offering to share.
Imagine a guest comes round and you fancy a cup of tea. Of course you also offer your guest one. If you don’t, and drink it in front of them, you are shockingly rude. Same if you open a packet of biscuits. (Or sweets.)
I was taught that manners begin at home. Any small civilities you would offer your guest you should also offer your family (like always saying please or thank you. Manners are not just for outsiders!). If you opened a bag of sweets in front of guests folks would be shocked if you ate them all yourself. Your family should be treated with the same courtesy. This is especially important when there are children at home. They learn first from their family.
This is not bringing children up to be rude, as some PP declared. This is modelling good manners in the home.
As for the specific issue, if your MIL has a particular aversion to sharing her food, then it would be appropriate to ask her in a quiet moment to wait until the children were in bed to bring out the sweets - you could perhaps say that it is too tempting for them to see them when they have already brushed their teeth.
If your MIL won’t agree to this, I think since you want to teach your children manners you really need to say something privately to them like, “Well, of course it is good manners to share, but you must always wait until you are invited to have some, even if you want them very much.” (Not saying such a thing in front of Granny, of course - because that would be very rude indeed. Grannies must never be seen to be rebuked in front of grandchildren!)
That will, of course, be very puzzling to children who are repeatedly told to share, and it is odd and confusing not to see their elders doing the same. Manners can be difficult to navigate, especially for children who are just learning.