First, define what is 'neighbour'. In your case, pixels 'A' and 'B' are connected if
abs(A.x - B.x) <= 1 && abs(A.y - B.y) <= 1. This is the rule that Microsoft Paint uses when doing flood fill.
Invalid-shape isn't closed can be easily detected using a Flood fill. A flood fill marks a non-empty pixel green. It then continues the flood fill with its neighbours, eventually filling the full shape. To do this, pick a random pixel, then find an empty neighbour. Do a flood fill starting from this neighbour with a unique color. Re-iterate over all pixels to ensure you have filled all of the areas. (Picture 2)
Now find out which colors touch the edges of your picture. These colors should be erased, as they do not constitute a closed space. (Picture 3)
Now, you want to detect lines that do not contribute to a filled area. To do this, mark all black pixel neighbours of a filled pixel in BLUE. (Picture 4)
All lines which are still black do not contribute to the edges of an area. They are invalid. (Picture 5).
Detecting your 'Valid, within a single stroke' requires a small extra step. For every invalid pixel, start a flood fill. If, during your flood fill, you touch the edges of two different areas, this line actually connects two areas and it is therefore part of your valid image.
You need to decide whether this algorithm is good enough. For example, drawing a thick edge by going back a few pixels will be marked as 'invalid', as this extra 'blob of ink' does not connect two areas.
You could improve this algorithm by adding a 'time' dimension: you give a list of pixels in the order in which they were drawn.
Finally, think about user experience. Drawing a 'V' shape will most likely result in >2 pixel neighbours for a new pixel drawn in the tip of the V. Can you algorithm that detects overlapping edges cope with that?