Why is the pituitary gland located in the brain?
The evolutionary pressure on the location of the pituitary is likely not the reason why it resides at the basis of the brain. Instead, its (partly) neural origin makes it anatomically (and functionally) part of the brain. Why would it migrate out of the brain when it doesn't have to? What would the evolutionary pressure be on increasing the length of the axons connecting it to the other parts of the brain? It is part of the brain, hence it is located there. It clashes with the principle of parsimony to have the pituitary evolve to a structure located farther from the brain. 

The neuroanatomy of the pituitary is schematically as follows (Fig. 1):


Fig. 1. Pituitary gland. Source: Imagekb.  

The posterior lobe of the pituitary gland consists largely of extensions of processes (axons) from the hypothalamus and are part of the neurohypophyseal system. There are neural connections to the brain and other centres of the hypothalamus. Hence, the posterior lobe is neural tissue. 

The cells constituting the anterior lobe of the pituitary gland are embryologically derived from an outpouching of the roof of the pharynx, known as Rathke’s pouch.