During his reelection campaign, when doing that involved great political risk, the mayor boldly raised both sales and property taxes in order to balance the city's ailing budget.
A) During his reelection campaign, when doing that involved great political risk, -> "That" doesn't have clear antecedent.
B) During his reelection campaign, when doing so involved great political risk, -> doing so is better, as we can see the mayor's actions, boldly raising both sales and property taxes. Let's keep it.
C) During his reelection campaign, when doing it involved great political risk, -> We have similar issue; we don't have clear antecedent for "it". Incorrect.
D) When, during his reelection campaign, to do that involved great political risk, -> During his ....is better modified by "the mayor". Secondly, we have a repeated error as "that", which doesn't have a clear antecedent. Incorrect.
E) During his reelection campaign, when to do it involved great political risk, -> Same as C. Incorrect.
So, I think B.