The Gemara (Pesachim 87b) states that Hashem performed a righteous deed with Israel in that he scattered them (pizron) among the nations.
Rashi explains that instead of being exiled to a single country, the Jews were scattered among several countries. G-d thereby ensured that the gentiles would be unable to destroy all the Jews at the same time [see Artscroll Pesachim 87b, note 49].
Yet, the Gemara (ibid. 118b) said that the reason Israel was scattered among the nations of the world was because Israel desired to be friendly with the nations. Therefore, G-d punished them measure for measure by scattering them throughout the world to live among those very nations (see Artscroll Pesachim 118b, note 49).
Was Hashem bringing the remedy before the affliction (see Megillah 13b) or was it a punishment?