Heading the ball is legal (as long as the ball was not thrown forward first!)

I was playing in a game many years ago against a team from an open prison, who had drafted in some soccer players to make up the numbers. One of their centres chose to head a high pass and the referee blew his whistle. He then said "I don't know why I did that! It is legal, but just looked wrong!" and gave the prison team the scrum.