Like the stitches in sewing, those in the side from both running and laughing all come from the verb stick.
The expression “to stick someone” is over a thousand years old and means “to stab” or “to prod.”
The stabbing or sticking of a needle through cloth in sewing is thus called a stitch.
And because both the pain in the side from running and that from laughing feels like you’ve been stabbed or stuck with something, these too are called stitches.