Why is root beer aged in a barrel?
That will depend on the specific brand and type of root beer.
Most commercially produced root beer will not 'age' but will go bad
over time. Those root beers made at small breweries that make small
batches, may change in flavors over time and improve as it
ages.