The law regulates possession as a fact not only to give it protection. It also regulates the relationship between the possessor and the owner of the thing. These are primarily the relations in connection with the expenses incurred for the foreign property.
These relations are governed by 3C (property law).
The possessor is not the owner, but he actually exercises the rights of the owner. He holds and uses the other's thing as his own - he gathers the fruits that it gives him. But in order to get benefits from the thing, the owner incurs expenses for its maintenance, so that the fruits can be obtained from it - he feeds the animals, builds, fertilizes and sows the land, plants trees. The owner of the land can become the owner of both the plantations and the buildings on it. Why then does the ruler spend, plant and build. He does all this because he thinks that he will become the owner through the acquisitive prescription, because he believes that after 5 or 10 years of continuous possession, he will make him the owner.
But that doesn't always happen. Before the expiration of the limitation period, the owner recovers the property, regains possession. At the same time, he gets his property improved, planted, built on. Its value has increased as a result of the expenses incurred by the owner. It turns out that one - the owner - has become rich, and the other - the owner - has become poorer. However, the law does not allow unjust enrichment - anyone who received something without reason is obliged to return it.