The romans had engineers and fire fighting crews. Nearly every society has had some kind of police/army/guard to enforce laws. Farmers actually opened the door to most other jobs/careers because people didn’t have to rely on themselves to grow or collect their own food which left more time to become an engineer, learn math, become a salesman or any other job that could be filled.
this link goes into light detail of how laws were written and enforced in ancient times, starting with tribal or clan based blood fueds and eventually turning to a more societal run and funded system.