Should a metal inline junction box on an extension cord be grounded?
If the box is metal, it should be connected to the ground conductor in the cord.

Imagine this scenario: the hot wire comes loose inside this box, and makes contact with the box itself (which is not connected to ground). You go to turn on the switch and touch the box while standing on the ground. Because the box is energized by the hot wire, and you're a path to ground, you get a shock (or worse).

The safety ground wire is designed to reduce this risk by ensuring any conductive surfaces are firmly bonded to ground. In the scenario above, if the box were grounded, a short would happen as soon as the hot wire contacted the box. This would flip your circuit breaker, so you'd know something was wrong. Way better than having the box sitting there energized -- an invisible danger just waiting for someone to touch it!

So: ground the box and ensure the ground conductor continues on past the switch. And make sure you're using a properly grounded outlet to feed this cord.