I'm not disagreeing with anything above (it is all so very right), but I'd like to add some nuance.
It is entirely possible that Papa Holmes was an actual country squire and Holmes has hereditary privileges conferred with that. But it is also possible that Holmes was referring to his ancestors in a more general sense, in the idea that "historically, we have been country squires" whether they still are or not, especially because depending on how many women there are on his father's side, it would have been easy to have descended from country squires but not be able to maintain the title. If that was the case, Holmes was still allowed to use esquire as the son of a gentleman, or the descendant of a gentleman, which was, at that time, a designation still found in the tables of precedence.
Though esquire as a title has kind of a complicated history, by the time that Holmes would have written "Sherlock Holmes, Esq.," it was considered proper for any man to address himself as such, ie it was often used in place of Mr, usually in formal or professional settings. Even today, when Buckingham Palace issues an invite to a man, it uses the Esq. designation as a mark of formality.
But there are so many other great reasons which demonstrate that Holmes Was Different, and that he is almost never on the side of the police or the establishment in general. Holmes definitely has friends who are titled nobility, or at least titled gentry. Victor Trevor's dad is a justice of the peace, and I believe Musgrave, of "The Musgrave Ritual," was either gentry descended from barons, or something like that. And back then, when you had money, you generally tended to hang out with people who had money, and not just for snobbery reasons. It was as much of a social insult for a rich person to try to be friends with a poor person as the other way round; I don't really have the space to explain why except to say that it was complicated and would have been seen as a power imbalance, among other things.
Holmes looked at all of that and went, "Yeah, I don't care," at a time when that might have meant a death sentence for his social standing, which absolutely determined things like where you could live, what sorts of activities you had access to, and how successful you were allowed to be. Moreover, think about how many times he dresses up as a member of the lower classes. That would have been absolutely unthinkable for most people of Holmes' standing at the time. He accepted anyone and everyone, and most of the times when he's angry with or uppity with clients, they are almost invariably wealthy or powerful or both. Someone without the comfort of independent wealth is not going to jeopardise their entire professional career by standing up to Lord So-and-So.
He kinda goes back and forth on what he tells clients about payment, and often says that they are at liberty, other than the fixed scale, to "defray" any expenses they deem appropriate, usually to rich people. Except for the Duke of Holdernesse, from whom he straight-up demands the reward money and then berates him for how the events of the case go, and it's because the duke put innocents in danger for the benefit of a blackmailer and his brutish accomplice. The duke even offers him double to keep his mouth shut, and Holmes refuses.
And he still doesn't tell the cops everything in that case, even though he would have been well within his rights to do so, simply because it is enough for him to see "the ends of justice are served" and that there's no reason to ruin a guy who was at the mercy of others and made bad decisions.
Over and over, Holmes' constant refrain is "I am not in an official position," which might as well be him shouting, I am not the cops don't you dare lump me with those idiots; everything he is and does is a reaction to how terrible the police are at that time. He'll often say things along the line of, I've left them all of the same evidence I had, and if they can't come to the right conclusion, why should I tell them? He actively hinders the police force as much as he helps them, and he is definitely not above flat-out lying to Lestrade, if necessary.
Modern Sherlock Holmes should be as anti-cop today as he was then. In fact, I bet today's Holmes would have to work against public smear campaigns the police would have in the press to delegitimise his work because he'd have no problem illustrating that they're as lazy and corrupt now as they were in the late 19th century, and I bet a fair amount of people would see him as little better than a criminal as the result.
Imagine the tumblr discourse.