Monasticism, at least within Christianity, manifests ascetical theology:
Christianity purposes to provide the means to follow Christ so we may enter eternal bliss. Christian perfection is a perfection of love. Attaining this love involves rejecting (or denying) that which is disordered within ourselves, learning to love and trust God, and growing in prayer life toward union with God. This may or may not be accompanied by mystical experiences (for example visions, rapture, or miracles). This progression and the various means by which to traverse it are described in the field of ascetical theology.
The logical extreme is the Desert Fathers who sold all they owned, gave the proceeds to the poor and went into the desert to dedicate themselves to practice prayer and mediation. This movement arose around the time that the church was becoming accepted by society at large. Since there were fewer opportunities to demonstrate dedication to the faith via martyrdom, Christians began choosing radical self-denial. This self-imposed separation from society is, in fact what the word monk means:
from Greek: μοναχός, monachos, "single, solitary" and Latin monachus
While solitude is important to ascetic practice, many religious orders focus on other vows such as obedience, poverty, silence and chastity. Keeping these vows can be difficult to impossible when in constant contact with people who do not respect them. So monastic orders often operate away from population centers.
However, many convents and monasteries are located in major cities—especially those with religious significance. Rome has so many that there is a service dedicated to helping tourists find accommodation in the facilities that offer guest rooms. Near where I live in Los Angeles, there dozens of monasteries. Presumably they don't focus on strict solitude, but on other aspects of the monastic life.