"Pipe trick" parsing of wikilinks (terminating a wikilink with a pipe and no argument to invoke some default behavior) fails when a wikilink contains both a colon-separated prefix (either a namespace or interwiki prefix, it doesn't matter) and an anchor; e.g. something like [[Foo:Bar#Quux|]] simply dumps that exact text into the viewed page instead of making any sort of wikilink. By contrast, mixing comma parsing with other syntax the pipe trick recognizes does work - e.g. [[Foo, Bar#Quux|]] is equivalent to [[Foo, Bar#Quux|Foo]].
The fix is to generate a wikilink instead. There is some previous discussion at the English Wikipedia's Village Pump (http://en.wikipedia.org/w/index.php?title=Wikipedia:Village_pump_%28technical%29&diff=prev&oldid=223151295) as to what the generated syntax should be, which supports parsing [[Foo:Bar#Quux]] as [[Foo:Bar#Quux|Quux]]; alternately, the "trim everything you can" approach would render it as [[Foo:Bar#Quux|Bar]], which is consistent with the comma example above.