Because social security is a tax. It’s not an insurance premium, or a pension plan, or a retirement account.
It’s not just teachers. People employed by state and local governments in various jobs *may *be exempt from social security. It depends on the state/local government- for example NYC employees can be exempt from SS if they don’t join a pension plan and contribute at least 7.5% of their pay into a deferred compensation account but NYS full-time employees must join the pension system and pay into SS.