Grant Barrett, The Oxford Dictionary of American Political Slang (2004) has this entry for wonk:
wonk n. an expert on intricate policies; (broadly) a studious or hardworking person. Also policy wonk. [Cited examples omitted.]
As presented here, wonk is clearly not a pejorative term. However, the limits of wonk as a positive notion are suggested by the same dictionary's entry for wonkism:
wonkism n. excessively deep knowledge of policies; the habits or character of a WONK. [Cited examples omitted.]
The implicit criticism embedded in the term wonkism would thus appear to be along the lines of "how could anyone care that much about something that boring?" This criticism is probably familiar to the many people at this site who are, in effect, grammar and usage wonks.
William Safire, Safire's Political Dictionary (2008) has this take on the term policy wonk:
policy wonk A grimly serious scholar of the tedious side of public affairs; stiff staffer steeped in study.
In the 1992 election, both Bill Clinton and Al Gore were known to delight in the minutiae of program development, causing Meg Greenfield of Newsweek to refer to them as "tough., ambitious, leadership-minded policy wonks."
Wonk is nautical slang for "cadet," but there is no clear relation between the terms. Sports Illustrated in 1962 wrote: "A wonk, sometimes called a 'turkey' or a 'lunch,' roughly corresponds to the 'meatball' of a decade ago." The suggestion that wonk may be "know spelled backward" may be dismissed as folk etymology.
In the 1984 Presidential election Sidney Blumenthal of The New Republic used the academic slang politically, referring to Walter Mondale's "thralldom to the policy wonks an wise men of the Washington establishment." In 2007 Hillary Clinton, presenting her concerns about healthcare costs to an audience of medical professionals at George Washington University, having been described in the local media as "a battle-scarred participant in the 1993 health-care overhaul failure," made a self-deprecating comment about not getting "overly wonky," using the adjective derived in 1978 from the noun.
It thus appears that hostility to expertise has long (at least since 1984) been embedded in the negative use of "policy wonk," "wonkism," and "wonky" in a political context. Nevertheless, there is also a hint of grudging admiration in the term "policy wonk," implying the same kind of uneasy respect that mainstream law students have for fellow students who plan to specialize in tax law.