It’s been customary law in Sweden since pretty much forever. But interestingly it had no explicit foundation in written law until 1994, when a short passage was added to the Swedish constitution: “Everyone shall have access to nature in accordance with ‘allemansrätten’” (“Alla ska ha tillgång till naturen enligt allemansrätten”).
Similar in Norway (though not added to the constitution) - it was for very long considered so obvious as to be unnecessary to codify, as pretty much the only area of Norwegian law treated similarly as in common law jurisdictions.
Which becomes even more interesting when you find out that allemansrätten is never defined in law.