In Buddhist Vajrayana tradition, Mahakala is considered to be one of the dharmapala (tib. chos skyong) — protector of the Teaching. Boddhisatva Avalokiteshvara used this terrifying manifestation to protect Buddhism and practitioners.
In every form, Mahakala belongs to the group of enlightened beings and is not worldly protector of the Dharma. In the universe there are many different classes of beings and according to the tantric texts among all of them, there are 8 types of very powerful and negative creatures. One of it, the type called «mahakala», which can create a lot of hardship for people. So in order to control their harmful energy, Avolokiteshvara is manifesting in their dimension with their appearance.