The Lord via the prophets had told the Judeans to bend their shoulders and serve the king of Babylon. If they did that, they would remain in the land that the Lord had given to their ancestors. However, if they did not obey the voice of God, and not serve the king of Babylon, then God would cease to have any sounds of mirth or gladness from the brides or the bridegrooms from the towns of Judah as well as the region around Jerusalem. The whole land would become a desolation without inhabitants. They had a clear choice, obey the Lord and the king of Babylon, or suffer the consequences. They were already in exile, because they had not obeyed the king of Babylon. As usual, Jeremiah and Baruch were pro-Babylonian.
The time frame is clearly the time of the siege of Jerusalem by the Babylonian army. However, Jeremiah was imprisoned in the palace jail by King Zedekiah of Judah. King Zedekiah had been installed as king by King Nebuchadnezzar in 598 BCE. However, he revolted against him and sought the aid of King Hophra or Pharaoh Apries (589-570 BCE) of Egypt. This led to the siege that lasted almost 2 years as the Egyptians tried to help King Zedekiah. Eventually, the Babylonians were successful. Meanwhile, King Zedekiah had Jeremiah confined to prison because, as always, Jeremiah was pro-Babylonian.