I've heard of four main ways this happen. First, someone in your neighborhood has the same GDO set with the same code. (Unusual, but possible.) Second, something is actually blocking the door from fully closing, or something is damaged or degraded that the unit seems to think something is blocking the door from fully closing, and therefore as you're driving away the door opens back up. (That's easy to check... wait for the door to go all the way down, and sits there for a second or two.)
Third, someone is deliberately going through neighborhoods with a GDO, playing with various codes, looking for garages to open to see if there is anything worth stealing. And finally, the motherboard or CPU of the GDO is damaged, causing the inconsistent behavior. That would require a complete replacement.