I come up with the sentence "I don't like him as a pianist, but as a judge" when considering "him" as a pianist. But can this sentence have two meanings when "as a pianist" refer to both "I" and "him"? Or can it only refer to the closer "him"?
Yes, without further context, it's ambiguous, and you should re-write it to reflect what you really want to say. It's doubly ambiguous, because you can't tell whether "judge" or "pianist" refers to you or to him.
As noted in the comment, a context could be made up where the sentence isn't ambiguous.
"He took points off for my pedaling, so I, as a pianist, don't like him as a judge."
"As a judge, I don't like him as a pianist."
"I don't like his piano playing, but his competition judging is excellent."