Why is the term 者 used in some job titles and not others? I see the term used for doctor, dentist and translator 医者, 歯医者, 翻訳者 to name a few, but not for teacher, mayor, secretary, etc.
~者 is a generic suffix which means "person who does the job of". It's usually used when there isn't a common alternative. It's typically used for a profession and doesn't require membership of an organisation. The emphasis is on the skills that they perform, not where they perform them.
医者 doctor (medicine-person) 歯医者 dentist (dentistry-person) 翻訳者 translator (translation-person) 研究者 researcher (research-person) 記者 reporter
In contrast ~員 means that you perform that role within an organisation (some jobs can use both of these). For example I'm both a 分子生物学の研究者 (researcher of the field of molecular biology) and 理研の研究員 (researcher of the RIKEN institute). 者 and 員 cannot be used interchangeable here.
会社員 employee (staff member) 会員 member (of an association) 研究員 research associate (for and institute)
Many positions are referred with the suffix ~手 instead. If one of these exists it is not natural to use ~者 for these. These imply that you perform a specialised role within a team or organisation. This is used for specialised skills and craftsmen. This emphasises that you perform these skills as part of a larger team.
若手 young (intern, apprentice) 投手 pitcher (baseball) 捕手 catcher (baseball) 運転手 driver 話し手 speaker 造り手 builder 砲手 gunner (military)
These are the 3 main suffixes for professions but there are many exceptions. There are many other suffixes for different jobs, particularly those with a long tradition will have an irregular suffix or one specific to a particular industry. Some of these clearly share similar skills or environment, such as white collar or blue collar jobs.
裁判官 judge 警官 police
作家 author 建築家 architect 政治家 politician
弁護士 lawyer 会計士 accountant
牧師 pastor 理髪師 barber 技師 engineer 教師/先生 teacher/instructor/professor
建具屋 joiner 鍛冶屋 blacksmith 仕立て屋 tailor
大工 carpenter 配管工 plumber 電工 electrician
The [many different] title endings often reflect [the partly historical] status or the way in which the person contributes when doing his/her job.
The 者 is typically used for jobs where the person possesses some rare / advanced / intellectual skills that allow him/her contribute thanks to the skills. And here we mean directly contributing, i.e. although leadership skills are advanced skills, "they don't count", as the contribution comes through boosting the performance of others.
I believe that the reason why e.g. a driver is untenshu, but an engineer can be referred to as a gijutsusha, relates to using gitsushusha to mean something more like a "meister" [with not so much stressing the "sensei" aspect of meister]. Today, a driver contributes individually, and it is a lot about also intellectual skills, while an engineer typically works as a part of a team, which would mean that if today inventing the words, an engineer would probably not be written with 者.