It's not uncommon for Greek myths to have several variations, and it's not always possible to reconcile different versions of a myth.
The Atlas and Perseus story is a late variation of the myth of the Garden of the Hesperides that appears in Book 4 of Ovid's Metamorphoses. In this version, the garden and its golden apples belong to Atlas, not Hera (who isn't involved at all). Another notable difference in Ovid's telling is that Atlas is a giant, not a Titan.
The story is built around a prophecy that a son of Zeus will steal the golden apples and with them the giant's glory. This was not Perseus' intention, the hero was only looking for a place to rest. However, when Perseus identified himself as a son of Zeus Atlas naturally assumed that he was there to fulfil the prophecy. Perseus was left with no other option than to turn Atlas to stone by using Medusa's head.