I certainly like this feature a lot, but I am uneasy about adding a query to every single topic page we display just for it.
My recommendation here would be to simply introduce a bit of manual process here when you grant the badge:
Add a staff note to the posts you assign badges for, it can link to the badge.
I feel this resolves the OP really cleanly and wonder if we should just have some way of doing this automatically by adding a checkbox. But a workaround exists now and is super clean.