It's a frequently asked question for a criminal defense attorney.
The answer - as is often the case - is complex, and moreover, it depends on one's sensibility, so it is impossibile to explain it in a few lines.
Some ideas, tough, without claiming to be exhaustive.
It is recognized at the supranational level that "such is the importance attached to the rights of the defense in a democratic society that the right to effective legal assistance must be guaranteed in all circumstances" (European Court of Human Rights, Grand Chamber, Nov. 2, 2010, Sakhnovskiy v. Russia); defending who is accused of a crime does not mean identifying with him, since "lawyers shall not be identified with their clients or their clients' causes as a result of discharging their functions" (United Nations Basic Principles on the Role of Lawyers, 1990).
A criminal defense lawyer does not defend the crime or the criminal, but rights: defending the accused tights, a criminal defense attorney defends everyone's rights and the rule of law.
Italian Constitution inequivocally rules that the right to defense is an inviolable right (a human or fundamental right, we would say today): our Constitutional Court has pointed out that the need to ensure the right of defense cannot be sacrificed for needs of another nature, which may be the expeditiousness or acceleration of the trial.
There is a close correlation between the exercise of the right of defense and so-called technical assistance, being necessary that in exercising the defense in court the party should always be assisted by a lawyer; if the appointed defense attorney is of course free to accept or not accept the assignment (but should avoid prejudicing the position of the suspect), the court-appointed lawyer, once he has agreed to be included in the list, has the obligation to defend the suspect.
And our Constitution is so sensitive is about the need to ensure a technical defense in court that it is requred that the Government provides legal aid of the indigent, i.e., the economically disadvantaged (means test).
After all, the presumption of innocence requires that the accused be considered innocent until irrevocably convicted: how, then, could the attorney refuse a defense on the basis of a charge (which is different from the judgment)?
Everyone has the right to be defended, in the interest of the community itself, which repulses or should repel summary trials, witch hunts, .. It's requested for the full implementation of the rule of law, a prerequisite of any democratic society.
And it should not be forgotten that many lawyers and defense attorneys all over the world have been threatened, tortured, killed because of their professional function (please see Nicola Canestrini, "Who defends the defenders? On endangered lawyers", New Journal of European Criminal law, Nov 2020).