Flipping the switch gives you 1, 2, or 4 deaths. It will always end up looping those three numbers, so after an infinite amount of time it has to be one of those three options.
All three of those options are less than 5, and they occur after an infinite amount of time instead of (relatively speaking) immediately.
From both a pure numbers perspective and a theoretical minimizing or delaying harm perspective, pulling the lever is the right move.