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.