The goal is to attain liberation in the body, by sealing in the energy of bindu in the head so that it is not lost.
Haṭha yoga is a branch of the largely spiritual practice of yoga, though it makes use of physical techniques; it was developed in medieval times, much later than the meditative and devotional forms of yoga. Its goals however are similar: siddhis or magical powers, and mukti, liberation. In Haṭha yoga, liberation was often supposed to be attainable in the body, made immortal through the practices of Haṭha yoga. Among its techniques were mudrās, meant to seal in or control energies such as kundalini and bindu. Khecarī mudrā is one such technique.
tl;dr - A spiritual practice of yoga in Hindu metaphysics.