The opposite is true. According to the Geneva Convention, refugees must flee to the next safe area in order to be recognized. It is only then that their illegal entry into foreign territory may not be punished. Many refugees arrive at a border from a safe territory, so they may be imprisoned.