The government can punish employees when the speech is pursuant to their position as a public employee. A DMV worker saying "lets go Brandon" to everyone coming through the door while they're at the desk is not protected speech. That DMV worker getting off the clock and attending a Trump rally is.
https://en.wikipedia.org/wiki/Garcetti_v._Ceballos