Stanley knows that the gold tube is a lipstick tube because he remembers his mother’s lipstick tubes.
Stanley recognizes the tube as a lipstick tube when he remembers that he has seen lipstick tubes in his mother’s house. The lipstick is the clue to hidden treasure.
Stanley is sent to Camp Green Lake reformation prison camp when he is accused of stealing a famous athlete's shoes. There is no lake, and nothing green. The boys spend all of their days digging holes as deep and as wide as the shovels they are given.
Stanley finds a gold tube when he and the other boys are digging holes. Since the rule is that the boy who finds the tube gets a reward, he gives it to X-Ray. As a result, the warden does not know where the tube is actually found.
Later, as Stanley sat sprawled across an understuffed chair, he tried to think of a way to tell the Warden where the tube was really found, without getting himself or X-Ray into trouble. (Ch. 16)
Stanley realizes upon finding the tube that it means that they are not just digging holes to build character. They are actually looking for something.
He suddenly realized where he'd seen the gold tube before. He'd seen it in his mother's bathroom, and he'd seen it again in the Warden's cabin. It was half of a lipstick container. (Ch. 22)
The warden is not a very nice woman. She keeps yellow-spotted lizard venom-poisoned nail polish and lipstick. Stanley makes the connection to Kate Barlow through the K.B. on the lipstick tube.
They later realize that the lipstick tube belongs to Kissing Kate Barlow, and the warden is looking for treasure in the desert outside Camp Green Lake. She is a descendant of Kissing Kate Barlow and that is how she knows about it.