It is evident from the Gemora that the law of the kingdom has the full force of halachah behind it. The Ritva writes that we do not find anyone that disagrees with this principle.
The Rashbam explains the rationale for this halachah: All citizens of a country voluntarily accept upon themselves to obey the king’s decrees and laws. All of their laws are therefore binding. Accordingly, one who possesses his fellow’s property based upon that particular country’s law, does not violate a prohibition of stealing at all.
The Rashba explains it differently: Since the entire land belongs to the king, he is entitled to chase anyone away from his land if he wishes, and he has the right to tax everyone for the privilege of residing in his land.
A difference between these two opinions may be if this halachah would apply in Eretz Yisroel with a Jewish king. According to the Rashba, it might not apply in Eretz Yisroel, for every Jew has an inalienable right to live there, and no king would have the jurisdiction to banish anyone from the Land.
The Ra”n in Nedarim 28a rules that this principle applies only in the lands of the exile. The reason for this, he explains, is that in these countries, the land is the property of the kingdom, and one is therefore obligated to abide by the laws and ordinances of the country in which he resides. But, in Eretz Yisroel, which belongs to the entire Jewish nation, there is no obligation to comply with the laws of a Jewish king. The Rambam and Shulchan Aruch both rule that this principle does apply to a Jewish king in Eretz Yisroel.