One version of the story states that Heracles wasn't actually the one who stole the golden apples. Once he reached the Garden of the Hesperides, he met Atlas who was holding up the world as punishment for waging war against the Gods.
Hercules had asked Atlas to get the apples for him and he would hold the world up for him in the meantime. Atlas had no problem agreeing with this task and set out to retrieve three apples of the the Hesperides.
Upon his return with the apples, Atlas refused to take back his duty, but Hercules tricked him by asking him to hold it for a moment while he adjusted his clothing for a more comfortable position. Atlas agreed and Hercules fled.
No one knew what to do with the golden apples at this point so Athena returned them to the garden where it is said they still remain.