In Sweden at least, "allemansrätten" as a law, comes from a change made in the 40s, to resolve conflicts between city dwellers need for "friluftsliv" and landowners, in-favor of the former.
Since 1994 "allemansrätten" is part of the constitutional law, securing the right for everyone to go anywhere under certain circumstances (cant stay longer than a couple of nights in the same place, cant stay within eyesight of a permanent resident etc etc)