Almost all the commentators have narrated that, when Muslims emigrated to Medina from Mecca, all the Arabs raised against them, except some who lived in Medina. So the believers lived in a state of anxiety and fear, so much so that they could not leave aside their arms even when they wanted to sleep.
They were asking one another that how long could that awful and uneasy situation last? Then the above verse revealed to console and encourage them, and to inspire them with the hope for a good future.