In heating and air conditioning applications, the term heat pump usually refers to easily reversible vapor-compression refrigeration devices optimized for high efficiency in both directions of thermal energy transfer.
Heat spontaneously flows from warmer places to colder spaces. A heat pump can absorb heat from a cold space and release it to a warmer one, and vice-versa. "Heat" is not conserved in this process, which requires some amount of external high grade energy to be expended.
Heat pumps are used to provide heating because less high-grade energy is required for their operation than appears in the released heat. Most of the energy for heating comes from the external environment, and only a fraction comes from electricity.