To me it seems entirely reasonable for the hole of a lock to be in the door and the "tongue" of the lock to be in the frame. Is there a reason we usually do it only one way?
The doorknob is attached to the door. This allows someone to twist the knob to retract the "bolt" and then, as a part of a continuing motion, pull on the knob to open the door.
It's hard to envision a scheme where the "bolt" could be tied to the frame while still allowing the door to be opened with one hand.
Setting the (several) other problems aside, a bolt sticking out of the door frame is a hazard. Not only can people get injured running into it, but loose clothing can get caught on it. Doors are chokepoints for emergency egress and are designed to keep out of the way when open so that the entire passage can be used for egress by panicking, distracted people. The door frame hoisting people by their own beltloops doesn't comply with this design.
Doors are pretty standard so the locks and keys can be universal with minimum adjustments. Door frames, however, are not standard. Look at the variety of exterior door frames. The thickness of the frames vary greatly, some are brick, fancy stonework, siding, decorator trim and molding, etc. meaning the locks would almost have to be custom made. Plus, the installation of the locks and keys would be much more involved drilling through bricks, etc.
Also, the strength of the frame for holding the bolt would be greater than the strength of the door holding the bolt.
There are sound reasons, some of which have been mentioned already, but don't neglect the role of convention - if we all do things the same way round, fewer different designs are needed, and there's no real benefit to putting the lock in the frame. There often isn't much frame before you get to the next bit of wall or similar, while the door is always going to be big enough to walk through and therefore have enough space to fit the lock. That said I have come across largely-glazed front doors with very limited space for locks. Upgrading the lock for greater security was challenging.
One modern reason that hasn't been mentioned is multi-point locking systems, where the lock mechanism in the door doesn't just lock a single tongue, but (on turning the key) engages bolts or hooks at several points on the door (usually at the top and bottom of the non-hinge side, plus 1-3 points on that side). This provides far greater mechanical strength than a single point lock.
An interesting comparison comes from electronic door locks, where there's a need to get wires to the part controlled by the security system. These are often combined with key overrides in the form of conventional locks, and then it's the striker plate on the frame that's wired.
This deals with issues like the tongue of the lock snagging on people walking through the door (mentioned in the comments), and means it's compatible with existing locks. At the same time it means no need for wires to be hinged.
Wood door. Might be a piece wood inside the door knob mechanism. Could also be wet. Wood swells when it gets soaked and wet.
Metal door the mechanism may just need a little cleaning and silicon spray lube. Safe to use on electric controlled doors. Just make sure power is off. The propellant is flammable..