It wasn’t long after Abraham almost tricked the Philistine king Abimelech into taking Abraham’s wife for himself, that he (the king) decided to make sure nothing like that ever happened again:
Genesis 21:22-23 About this time, Abimelech came with Phicol, his army commander, to visit Abraham. ‘God is obviously with you, helping you in everything you do … Swear to me in God’s name that you will never deceive me, my children, or any of my descendants. I have been loyal to you, so now swear that you will be loyal to me and to this country where you are living as a foreigner.’
Abraham agreed, but there was this issue of a well that he’d dug: Abimelech’s servants had taken it by force from Abraham’s servants, and Abraham wanted it back. The whole thing had happened without Abimelech’s knowledge and so the matter was settled favourably, with some extra livestock thrown into the deal to guarantee Abraham’s rights to the well, as Abraham explained to Abimelech:
Genesis 21:30 Please accept these seven lambs to show your agreement that I dug this well.
Abimelech agreed. It later turned out to be a strategic agreement for Abraham.
Although Abraham lived as a foreigner in that land, Beersheba would be in the far southern part of the future Israel.