In the US this comes from the copyright clause of the constitution.
"To promote the progress of science and useful arts, by securing for limited times to authors and inventors the exclusive right to their respective writings and discoveries."
The problem this was trying to solve was how do you incentivize people to create in order to 'promote the progress of science and useful arts' for the public's benefit. Limited time monopolies are the means to get to the overall goal of promoting the progress of science and useful art for the public's benefit.
Originally this limited time was 14 years with the ability to renew (once for 28 years max) - it also wasn't automatic and had to be registered. Today it's automatic and 75 years after the death of the creator (or 95 years for contract work) and even worse this change was retroactive. The retroactive change isn't within the original spirit of the law since people don't need to be incentivized to create something they've already created. You also can't opt out of it for works you've created, the best you can do is permissively license something (just stating 'this is public domain' doesn't do anything).
Not only does this lead to problems with orphan works, but massive amounts of culturally relevant material is now off limits for new people to create with - this inhibits new work except under the narrowly defined free use exceptions. Inhibiting progress of science and useful arts is the opposite of the original intent.
Copyright law today has mutated into protecting the profit of the rights holders and extending the length indefinitely, but only by a handful of years at a time so the supreme court can't rule it unconstitutional since it's technically a 'limited time'.
All of this was never intended to stop not for profit sharing of content and the law does a lot more bad than good - we want the minimum limited time restriction to encourage creation for the public benefit, not years after the death of the creator so the family and subsidiary companies can profit forever.
In the case of the journals it's even worse since they're exploiting the researcher's need for prestige and blocking access to publicly funded research. It's a corrupting influence on science and incentivizes scientists not to cooperate. These journals hold science back and offer no real benefit - maybe scihub will actually force them to provide value, but even if it kills them everyone will be better off.