Again, the hiring decision isn't based just on teaching prowess. His emails to department members show a sense of entitlement and disrespect toward people who are directly involved with his hiring decision. Why would they want to keep someone like that?
Don't forget, he didn't get fired. He simply didn't get his contract extended. He was never guaranteed a permanent position. The math department had no wrongdoing here. They didn't want to keep someone that was widely disliked by the department. And does it matter that a lot of students like him? The most important thing is that the students learn, not that they make a friend. It's certainly not a negative to be a friendly instructor, but it really isn't a key factor here.