How is this done and who initiates the writ?
I wish I knew, but I seem to remember that a writ of mandamus is an order for an official to do his job.
These two articles explain it.
http://gunwatch.blogspot.com/2014/10/pa-house-moves-to-spank-scofflaw.html
http://gunwatch.blogspot.com/2014/11/pa-local-governments-file-lawsuit-to.html