Poor Sherlock. He has been ridiculed his whole life. By his mean brother Mycroft, his evil sister Eurus, his classmates/colleagues… All of what Sherlock was exposed were mean comments and people mocking him. His friends made fun of his ideas and theories, his brother called him an idiot… That’s why he’s mean to other people. He doesn’t know what “nice” is. He has never been treated nicely. Yes, his parents were probably very nice to him, but that’s all. People didn’t take him seriously and thought he was stupid and that’s what he learned and therefore how he acted towards other people. That is until he met John Watson. The guy who marveled at and complimented his brilliance. That is why, over the course of the show, Sherlock gets kinder and kinder.