I have removed a bathroom door and installed a sliding barn door on the other side of the wall. The door frame in the bathroom now has the open sores of where the three hinges came off. The house was built in 2004 and all the door frames are mdf/cardboard. The door frame is painted with high-gloss paint. What's the best way to fill this in to protect it from moisture and smooth it over?
If your doorframes are MDF any patching is going to be visible to some degree. I would try filling it (with slight overfill) with wood putty and sanding it as smooth as you can using finer grit (220) for the finish. It all depends how particular you are - it's very difficult to get a perfect mend on this.
The only other option is replacing that side of the frame which would take considerable time and effort since it's structural to the door. In case you or a future homeowner wants to put a door back in you need to make sure it's attached properly and shimmed.
For the best match, cut a thin piece of the same MDF material to fit, and glue it into place with wood glue. MDF is very easy to work with so this would be relatively easy. If the fit is good enough, the glue will fill any of the cracks, or fill them in afterwards with a mixture of wood glue and MDF dust. Keep glue off the surface as it will affect the sanding and painting properties in a negative way. You can keep glue off in the same way as when painting, by applying masking tape to the surface.
Sand any imperfections smooth and paint to match. It's very difficult to match paint perfectly so you might choose to paint the entire flat surface area. The nearby surfaces often don't need to be painted because the lighting will hit them slightly differently thereby making any slight difference undetectable.
If you really want the "best" way, it's going to be to remove the existing door casing and replace it with a smooth 1-by board. Like a 1x8 or 1x6 ripped to the proper width. That would remove the unnecessary door stop trim and give you a nice, smooth opening.
If that sounds like too much work (and it is quite a bit of work), then filling the old holes and hinge locations and sanding smooth is your best bet. You may have to build up the hinge spots with a few layers of fill, but it should be possible. Using a long block sander can help smooth over that area. A small sander will tend to leave a concave area where the fill is going unless you're very careful.