What purpose does mercury dichloride have in fireworks?
Most likely, mercury was used as a colorant, specifically red.  This list shows mercury providing a red color in flame tests, and the same would presumably be seen in fireworks.

Several other, less dangerous elements also give red or reddish colors.  This site identifies lithium as providing the color in red fireworks, and also mentions lithium carbonate specifically.

Be safe this 4th, handle fireworks with care if you do so at all!