I've had that happen as well. It's like a 'blacksmith puzzle' -- the chain got that way without being taken apart, so there is guaranteed a way to get it back without taking it apart.
When I take a rear wheel off, I first shift to the smallest cog because then I know which cog to put it back on, and that's the easiest cog to do it with. Undo the QR, grab the RD by the pulley and pull it way back as far as possible, then take the wheel out. Holding the RD and having the chain somewhat stretched out, it is under control at this point. Let the RD go back to its neutral position, and watch the chain as you do it that it doesn't get kinked. It might help keep it untangled if you put the chain on the big ring in the front. It might also help if you have like a chair or something nearby with a stick or a screwdriver sticking off the edge, holding the top (upsidedown bottom) half of the chain up in the air until you're ready to put the wheel back in.
Also that's a great video up there in post 2, should make everything clear. When you have the bike upside down, don't let the chain fall off the crankset and over the pedal, and don't let top (upsidedown bottom) of the chain fall down past the derailleur