Not necessarily. For example, in the Netherlands one cannot be punished for being illegal here[0].
Edit: added a link for clarity.
[0]: http://www.dutchnews.nl/news/archives/2014/04/cabinet_drops_...
Edit: added a link for clarity.
[0]: http://www.dutchnews.nl/news/archives/2014/04/cabinet_drops_...
This doesn't make sense as a sentence. Surely the Netherlands has a justice system and prisons, and surely those people in prison are there because they were convicted of doing something illegal. So it stands that you can and will be punished in the Netherlands for doing something illegal.
"Illegal residence is only punishable if the party involved has been declared 'undesirable'" (http://en.justitiaetpax.nl/project/aliens-detention-in-the-n...)