The setting of Two Gentlemen can be a bit confusing because, in the 1623 folio edition (the only early copy of the play we have), there are several inconsistencies about geographic location. Here's what you need to remember: the play begins in Verona (Valentine and Proteus's home town) and then moves to the Duke's court in Milan. Then most of the cast travels to a forest (somewhere between Milan and Mantua).
The Duke's court in Milan is portrayed as a worldly, cosmopolitan kind of place. This, after all, is where the fathers of Proteus and Valentine send their sons to learn a thing or two about the great big "world." This becomes clear when Panthino advises Antonio:
Twere good, I think, your lordship sent him thither:
There shall he practise tilts and tournaments,
Hear sweet discourse, converse with noblemen.
And be in eye of every exercise
Worthy his youth and nobleness of birth. (1.3.4)
We talk about the forest in "Symbols," but we've got to mention it here as well because it's pretty important. When Valentine gets booted out of Milan for trying to elope with Silvia, he flees to a forest somewhere between Milan and Mantua, where he quickly becomes the leader of a band of outlaws (who have also been banished from court). Although Valentine misses Silvia and thinks that keeping his crew of thieving outlaws out of trouble is hard work, things are hunky dory in the forest. He says so himself: "How use doth breed a habit in a man!/ This shadowy desert, unfrequented woods,/ I better brook than flourishing peopled towns" (5.4.1). In other words, Valentine could get used to the simple life. In the forest, he doesn't have to worry about the chaos of court or the problems that come with his romantic interests.
Eventually, all of the major characters wind up here as well and the problems that follow them are quickly resolved. The Duke gives Valentine permission to marry Silvia, the outlaws are pardoned by the Duke, Proteus falls back in love with Julia, Valentine and Proteus become best buds again, and so on.
What is this? A magic forest? Sort of. Here's what literary critic Jean Howard has to say: "The utopian possibilities for social renewal in a world beyond the walls and customs of the city are celebrated in this play as they are later to be in A Midsummer Night's Dream, As You Like It, and other Shakespearean romantic comedies of the 1590s" (Introduction to Two Gentlemen of Verona, The Norton Shakespeare, 2008). In other words, the forest is a space where characters can escape from their problems and repair the social relationships that they've managed to screw up. Shakespeare really likes this convention – he's always sending his characters on vacations into the woods or the countryside, where life is simpler and the air is cleaner.
For women, however, the forest is also a place of potential danger. This is where Silvia is nearly raped by Proteus (5.4) and it's also where Valentine makes his band of thieving brothers promise not to hurt any women (4.1.12), which sort of implies that women get hurt in the forest all the time. Eventually, however, the forest is where Julia's relationship with Proteus is mended and where Silvia is engaged to her sweetie, Valentine. This, by the way, is Shakespeare's way of "restoring social order" for the ladies – by hitching them to husbands.