Usually a door opening by itself is caused by the door being hung by the casings. This is a poor pitiful way of installing doors that in theory speeds the job consideraby.The fact is that later on, the doors become almost unuseable. They won't stay latched, they won't stay open, they won't stay closed or they begin to drag the floor in their swing.
Unfortunately, the only way to fix these doors is to remove the casing on the side opposite the hinges and latch. Then you can shim behind the hinges, plumb the door so it won't swing at will, and anchor the jambs solidly to the walls. For shims you can use wood, vinyl siding, shingles, whatever will stack solidly and can take a nail through it.
If the jambs are solid and the latch is fine, but the door wants to swing on it's own, it could be many problems from a settling problem under the wall to an out of plumb wall or door install. You can loosen the hinges and use thick paper shims to correct some of this, but this fine tuning won't always work. Also on older homes, the top hinge pin sometimes wears out and can be swapped for a lower pin which is sometimes just enough to solve some of these problems..
Hope you find something you can use here