After Harry works out that the snitch might open in his mouth and he tries it, it fails to work. But why then did it open when Harry told it he was about to die? How also does the clue "I open at the close" link to this?
The reason it was meant to work that way was because the Resurrection Stone was only needed - and safe - for Harry once he became the True Owner of the Hallows, the Master of Death. Which according to Dumbldored ("King's Cross", DH):
“I was scared that, if presented outright with the facts about those tempting objects, you might seize the Hallows as I did, at the wrong time, for the wrong reasons. If you laid hands on them, I wanted you to possess them safely. You are the true master of death, because the true master does not seek to run away from Death. He accepts that he must die, and understands that there are far, far worse things in the living world than dying.”
The trigger for that, for Dumbledore, was specifically Harry's acceptance of his own death once all the Horcruxes save Nagini were gone; and Snape had told Harry about himself being the Last, Seventh, Horcux as we see in Snape's memories.
“Precisely. If there comes a time when Lord Voldemort stops sending that snake forth to do his bidding, but keeps it safe beside him under magical protection, then, I think, it will be safe to tell Harry.”
“Tell him what?” ...
“Tell him that on the night Lord Voldemort tried to kill him, when Lily cast her own life between them as a shield, the Killing Curse rebounded upon Lord Voldemort, and a fragment of Voldemort’s soul was blasted apart from the whole, and latched itself onto the only living soul left in that collapsed building. Part of Lord Voldemort lives inside Harry, and it is that which gives him the power of speech with snakes, and a connection with Lord Voldemort’s mind that he has never understood. And while that fragment of soul, unmissed by Voldemort, remains attached to and protected by Harry, Lord Voldemort cannot die.“
So, once Harry accepted that he was about to die and that he must do it to defeat Voldemort - that was when Harry would become a Master of Death and could safely possess the Resurrection Stone.
"I open at the close" - "close" means "closing", the end of one's life.