You may have a deadlocking latch bolt, which in addition to a normal door latch has a plunger. When this plunger is retracted (which happens when the door is closed), the spring loaded mechanism on the latch is disabled. This prevents someone from using the credit card trick to open the door from the outside, so the only way to open the door is by unlocking it and turning the knob. In other words, it's for security.
Sample image from doorware.com, no affiliation
My guess, assuming this is an external locking door, is that this plunger is either jammed or some of the internal mechanisms that it activates have jammed. You can unscrew the door knob and remove both sides, then unscrew the latch and pull it out of the door. From there, try some lubricant (silicone spray and graphite powder are my preferred lubricants for locks, WD-40 will quickly dry and attract dirt). And if it still doesn't work, it's probably time to go to the store to pickup a new doorknob.
I am not a contractor, and this is a real do it yourself type approach. This is provided at your own risk, and I assume no liability for damage.
The only thing I can think of that is going to auto reset in the way you've described is a device powered by gravity. Everything else ( anti-kick devices installed backwards, anti slam devices) either won't allow the door to close or need to be manually reset.
I picture a small piece of plate steel rather than wood, for durability, that has a hole bored in it, along the top edge, perhaps in the center, perhaps 1/4" - 1/2".
Through this hole pass a bolt whose body is less than the hole size, but whose head is too large to pass through (you'll likely end up with 1/16" or 1/8" clearance on the inside of the hole, which should be fine. You'd want to use a bolt that is threaded right to the head as opposed to those that are only partly threaded. You might need to scratch your head a little to get the bolt length right, but I'm thinking that a 5" bolt with 1" into the wall might be enough (remember that at the corner of the door the gap will be much more than 4").
You will also require a self locking nut for this bolt, some washers and some sort of threaded hole you can install into your door frame (there are hammer in threads available, just make sure you plan ahead size wise, some people would just hammer in a nut).
To support this contraption, I picture a wire back to the wall, but a firm brace like a piece of rod or wood could also be used. The brace should look like an upside down triangle when it's installed.
Drill a hole in the top of your door frame, within an easy reach of the door handle (you'll need to reach it to get out of the room), and install the threading. Make sure that you leave enough room for the plate to swing upside down and still clear the door.
Place the loop of wire/support rod on the bolt next to the head.
Place a washer on the bolt and pass it through the plate. Place a washer on the bolt (so that the washers are sandwiching the plate) and put the nut onto the bolt, so that the washers and plate are close, but not firm (if it's too firm, it's too hard to swing it out of your way).
If the door blows closed, the nut will prevent the plate from sliding back to the door frame and thus striking your pet.
When you want to open the door, you swing it open (the plate is between the door and the jam).
When you DON'T want the door to close, do nothing, (the plate's in the way) and gravity will reset the material.
When you DO want to close the door, swing the piece of material out of the way and close the door. When you want to get back out, you'll have to push the plate out of the way again, and leave, gravity resets.
Ok so that's really a lot of text, but it's a diy description ...
I personally think it's easier to use an anti-slam device and put it somewhere remarkably annoying so you can't forget it. Something like this, put over your sink faucet while you use the washroom. They come in really big foam finger style designs, that would probably help give your pet time to get out of the way or prevent some injury.
Best Answer
Change the lock to either a magnetic one - which will always open with a push or pull or a spring-loaded roller one that will do the same.