In Scotland, the term "wee" is used to mean small. In English, "wee" is used to mean urinate. So the joke is playing on the different uses of the word "wee". The joke could be understand as the person have a small accident, or a small urinary accident. 
The incontinent Scotsman had a wee accident .