This is called Chording, flagging like that only works when there are only tiles of that number around the tile. You can see how many there are by the outline around your cursor tile. If there are more or less cells around a number tile than what it sums to, it will not work.