Ben Gunn knows it will be safe for Jim Hawkins to go to the stockade because of the flag that is flying from the stockade.
When they come in sight of the stockade (this is right at the start of Chapter 19) they see the Union Jack flying there. Ben Gunn says that is proof it is safe. Jim says that he figures that Long John Silver might be flying it. But Ben says that there's no way he would be. Only pirates ever come to this island so Silver would be flying the pirate flag if he were the one inside the stockade.