Comey’s decision is indeed self-serving in a couple of respects. First, he probably dislikes Trump more than he dislikes Hillary and believes that a criminal referral could increase the likelihood of a Trump presidency. Second, he probably realizes how uncomfortable his position would be as FBI director if he recommended charges against Hillary and she later became president (and his boss), not to mention the disapproval that he would receive from the Obama administration.
The mechanism by which he reached his decision was the exercise of discretion that exists at all levels of the criminal justice system. The decision to charge a suspect is often based on a subjective impression of how the “interests of justice” would be best served. This can include considerations other than evidence of actual guilt, such as the “political exception” in which the legal system is often (not always) reluctant to preempt the electorate in choosing their leaders. Of course, this exception can be—and often is, as here—applied in a misguided, self-serving, inconsistent and incoherent manner that actually harms the public interest and undermines respect for our system of government.
What you describe is nothing more than the fed version of a “good ole boys” club. Nobody inside the club is prosecuted, everybody inside the club has immunity.