Make sure the hinges are completely in (the peg) part.
I like to use or make door stops. You can cover a brick with material, add a bow for the Christmas season or something else and it's done.
Lowes and home Depot sell rubber door stops, shaped like a wedge, to keep doors open. Place the stop beneath the lower, outer edge.
its a bathroom door so I can't keep a doorstop right now ! have a rug under the door to keep it from closing
Check the hinges and make any necessary adjustments. My doors stay open but move easily in a breeze when I have all the doors and windows open so I have several decorative doorstops.
If you have this option, you could install an eye bolt and clip to keep the door open. Those using the bathroom need only release the clip.
If your door is closing because it is out of plumb then the correct repair is to remove and save the trim, cut the nails holding the door frame in place, shim to re-level and plumb, nail back in place, replace trim.....ugh! Lots of work.
.....here's the "down and dirty" quick fix....
Remove a hinge pin and bend it a little (not too much because you have to tap it back into place). The slightly bent pin creates a little bit of drag and friction in the hinge, enough to slow the free swing of the door and hold it in the position you put it.
If the door still swings after bending one pin, remove another pin and do the same thing.
My previous home moved alot--wet winters caused my doors to swing open--dry summers and my doors drifted the other way. This bent hinge- pin trick worked perfectly to keep them in place.
Kc's suggestion is my go to for this issue because it's so easy. Another solution, but not as quick, is to take a piece of thin cardboard or even a business card and put it behind the hinge. You will need to remove the door and the bottom hinge. Cut it to fit the hinge mortise. Line up the holes from hinge and poke holes through the cardboard. Reinstall the hinge with the cardboard behind it. Also check out this article: