Origin: This expression dates from the 1800s, to describe people who just did not fit into situations they were in. They essentially did not have the temperment, skills, or knowledge. Sometimes the words in this expression are switched to 'square peg in a round hole.'
Possibly this predates the 1800s as the expression is used by Zen Master Dogen in "Shobogenzo", his Zen Buddhist Masterpiece entitled "The Treasure House of the Eye of the True Teaching".