To be in stitches is to be in such a paroxysm of laughter as to be in physical pain. The allusion implicit in the phrase is to that of a sharp pain - like being pricked with a needle.
The phrase was first used by Shakespeare in Twelfth Night, 1602.
If you desire the spleen, and will laugh yourself into stitches, follow me. Yond gull Malvolio is turned heathen, a very renegado; for there is no Christian, that means to be saved by believing rightly, can ever believe such impossible passages of grossness. He's in yellow stockings.
Despite the usage in Shakespeare, the phrase didn't become established in the language and there are no other records of it until the 20th century. This entry in The Lowell Sun, in July 1914, is the earliest non-Shakespearian record that I can find:
"There's a new face among the members in Ben Loring, a natural-born comedian, who seems to have no difficulty whatever in keeping his audience in stitches of laughter and glee."
See other phrases and sayings from Shakespeare.