Problem seems solved; reason very likely found.
After years of taking a break from GPG, I took the work up again. First I
upgraded to GPG version 1.4.14 (the currently latest version). Then, in
reviewing my previous work, I found that in the interprocess dialog between my
program and gpg.exe I had been sloppy and had caused race conditions. In the
process of improving these dialogs, the described problem disappeared, i.e. did
not come up again despite some intense testing. I hope it stays that way!
Thus, although I cannot put my finger on "the one" code change that did it, I
tend to think now that the problem has been mine from the beginning, namely that
I had programmed race conditions. The intermittent nature of the original
problem supports this assumption.
I apologize for any inconvenience that has caused.