There was no one purpose for gardens in the ancient world. All the suggestions you mention are valid. For example, emperors often times bequeathed in their will or created while they were alive to make gardens, so that people would have a beautiful place for relaxation. It also simultaneously showed their generosity. Like Augustus stated in the Res Gestae (a monument of his accomplishments, which is now in Ankara Turkey), he left Rome a city of marble.
The ancient world was based on benefactions. In Greek it was called, "philotime." This basically meant that the social elite has a desire to gain glory by doing great works for people in society. We even read of this in the New Testament. There is a person named, Eratus in 1 Corinthians. He was an aedile in the city and he built a road for the city at his own expense. This was not a garden, but it was for the same purpose to show off wealth and benefit people.