The tongue-in-cheek figure of speech is used to imply that a statement or other production is humorously or otherwise not seriously intended, and it should not be taken at face value.
The phrase was originally meant to express contempt. By 1842, however, the phrase had acquired its contemporary meaning, indicating that a statement was not meant to be taken seriously. Early users of the phrase include Sir Walter Scott in his 1828 The Fair Maid of Perth.
Putting one's tongue into one's cheek was originally used to signify contempt. For example, in Tobias George Smollett's The Adventures of Roderick Random, which was published in 1748, the eponymous hero is taking a coach to Bath and apprehends a highwayman. This provokes an altercation with a less brave passenger:
He looked back and pronounced with a faltering voice, 'O! 'tis very well—damn my blood! I shall find a time.' I signified my contempt of him by thrusting my tongue in my cheek, which humbled him so much, that he scarce swore another oath aloud during the whole journey.
The phrase appears in 1828 in The Fair Maid of Perth by Sir Walter Scott:
The fellow who gave this all-hail thrust his tongue in his cheek to some scapegraces like himself.
It's not clear how Scott intended the phrase to be understood. The more modern ironic sense appears in the 1842 poem "The Ingoldsby Legends", in which a Frenchman inspects a watch and cries:
'Superbe! Magnifique!' / (with his tongue in his cheek)
The ironic usage originates with the idea of suppressed mirth—biting one's tongue to prevent an outburst of laughter.