Long before the events of "Dreamscaperers," Stan Pines placed the deed of the Shack inside the safe in his office. Gideon, knowing well of this, attempts countless times to try and steal the deed. Most notably, in "Little Dipper," he mentions it when he tries to threaten Stan into giving him the deed with Cursed Egyptian super termites.
Afterwards, the deed is seen again in "Dreamscaperers" when Gideon tries to steal it from the safe in Stan's office. Stan stops him, places the deed back in the safe, and locks it. This forces Gideon to summon Bill Cipher which he then commands to go inside Stan's mind to find the memory of him inputing the combination to the safe. After hearing this, Mabel, Dipper, and Soos band together in order to stop Bill. When Gideon witnesses Bill's failure he has no other choice but to resort to "Plan B," the use of dynamite, which he uses to break into the safe and steal the deed.
In "Gideon Rises," the deed is in Gideon's possession, who now claims that Stan has given it to him, thus by Gravity Falls law makes him the owner of the Mystery shack. Stan, Mabel and Dipper try to tell the citizens of the town that Gideon is lying and that he should be arrested, but Gideon has his thugs remove them from the Shack's grounds. Far later in the episode, Gideon has been defeated but before he is sent to prison, Stan shakes him, making the deed and other objects fall out of his pockets. He then picks up the deed and steals Journal 2 at the same time. After regaining possession of his property, he announces that the Mystery Shack is back in business.