Headbutt is a move that can be used out of battle to interact with certain trees that can reward you with items or Pokemon battles. This is the only way to encounter some Pokemon. You must have at least 155 happiness on the Pokemon with headbutt for it to work outside of battles.
Headbutt can be taught by the Move Tutor in Ilex Forest in the Johto region.
Certain Pokemon can also learn the move by leveling up. Some Pokemon that can learn headbutt by leveling up include: Slowpoke, Slowbro, Slowking, Seel, Dewgong, Drowzee, Hypno, Cubone, Marowak, Snubbull, Granbull, and others. A complete list and the levels they learn it can be found here.
The ability Synchronize does not work with headbutt (or rock smash or static encounters.)