It´s what made German beer famous in the world, since it guarantees a high quality of ingredients (only water, hop and barley are allowed) and a careful processing, but it wasn´t made to ensure the beer quality – the Duke of Bavaria enacted it in the year 1516 to protect the bakeries. Since the breweries paid better for the grain than the bakeries, the last one was always short on wheat and couldn´t bake enough bread to feed the working people – who ended up in a pub, drinking beer.
For obvious reasons the Duke rather had the people eating than drinking, so he prohibited to brew beer with wheat, the breweries had to use barley. (the famous Weissbier from Bavaria came up later)
Today the decree is the oldest one in the world still in power and I´m pretty sure, it protected German breweries to not make the same mistake other countries did: to produce cheap but tasteless beer.