ckubs is your extension code somewhere online ? It's hard to give directions without more than that.
Extensions are usually pre-compiled with Gulp and use some Flarum-specific code to be booted with the remaining of the single page app. It's possible the way you call jQuery creates issues if it's not running at the time Flarum expects it.
Also be careful with those .html() calls, I see potential for XSS vulnerabilities ! There's a possibility an href attributes contains more than an innocent link if it's user input.
Use jQuery's methods to set the attribute or better, implement your lightbox with Mithril (if you're able to).