What is happening is the door latch switch, that tells the control board that the door is indeed closed, has failed.
The reason you can get it to work is because the electrical contacts will eventually make contact after being warmed up by just the action of opening and closing them (the contacts). Friction that is developed by the metal striking, and / or rubbing each other will cause a small amount of heat if you do it enough in rapid succession. They then will function as long as they have current being sent through them. This current is arcing the gap. This causes heat that keeps the contacts warm and they will continue to function (albeit improperly) as long as they are warm. this includes a short period after the unit is turned off. Once cooled they must again be warmed up to make the contact.
Mind you this is only a theory and not something out of a service manual. But the way you describe the problem and the cure it seems logical to me.
Any way you look at this you will need to have it looked at by a service person. Due to the inherant dangers of magnitron tubes I do not recommend that an unqualified person do any repairs on them. They are as Im sure you know very dangerous.
Microwaves these days are a very inexpenxsive commodity. This tends to make most repairs cost prohibitive except for the very high end doeverythingbutwaxyourcar models.
this said you may wish to look int a new unit. You can get a deceny one for $80.00 and a inexpensive one for $30.00.
If this answer satisfies your question please click on the accept button. I will not be paid if you dont.
You can always ask follow up questions after you accept. I will be here to answer them.
If for some reason you are not happy. Please tell me what I can do to put a smile on your face.
Thank you for using Just Answer. Please tell someone about us.
Best regards; The Home Smithy
After you have accepted it is important that you leave positive feedback.