Sherlock Holmes is no Dark Knight: he's not zooming around London dispensing vigilante justice. But he is a private detective, which means that he too doesn't have to obey the rigid rules of police work. For all of Holmes's talk about being unemotional and so on, he makes judgments based on feelings all the time, as when he lets James Ryder go at the end of "The Blue Carbuncle" or when he releases John Turner at the conclusion of "The Boscombe Valley Mystery." Once he's solved a case, Holmes has a lot of leeway to decide whether the wrongdoer deserves mercy or not. And his decisions are not always the purely logical choices he might have us believe.
Smaller problems such as Mary Sutherland's exploitation by her parents in "A Case of Identity" give Conan Doyle a chance to think about the place of morality outside of its strict legal definitions.
By making Holmes subject to error and to accident sometimes, Conan Doyle inserts an additional layer of suspense into his detective story formula.