Zedekiah son of Josiah succeeded Jehoiachin son of Jehoiakim as the king of Judah. He was appointed by King Nebuchadnezzar of Babylon.
References for Jeremiah 37:1
But neither King Zedekiah nor his officials nor the people who were left in the land listened to what the LORD said through Jeremiah.
Nevertheless, King Zedekiah sent Jehucal son of Shelemiah and Zephaniah the priest, son of Maaseiah, to ask Jeremiah, "Please pray to the LORD our God for us."
Jeremiah had not yet been imprisoned, so he could come and go as he pleased.
At this time the army of Pharaoh Hophra of Egypt appeared at the southern border of Judah. When the Babylonian army heard about it, they withdrew from their siege of Jerusalem.
References for Jeremiah 37:5
Then the LORD gave this message to Jeremiah:
"This is what the LORD, the God of Israel, says: Tell the king of Judah, who sent you to ask me what is going to happen, that Pharaoh's army is about to return to Egypt, though he came here to help you.
Then the Babylonians will come back and capture this city and burn it to the ground.
References for Jeremiah 37:8
The LORD says: Do not fool yourselves that the Babylonians are gone for good. They aren't!
Even if you were to destroy the entire Babylonian army, leaving only a handful of wounded survivors, they would still stagger from their tents and burn this city to the ground!"
When the Babylonian army left Jerusalem because of Pharaoh's approaching army,
Jeremiah started to leave the city on his way to the land of Benjamin, to see the property he had bought.
But as he was walking through the Benjamin Gate, a sentry arrested him and said, "You are defecting to the Babylonians!" The sentry making the arrest was Irijah son of Shelemiah and grandson of Hananiah.
"That's not true!" Jeremiah protested. "I had no intention of doing any such thing." But Irijah wouldn't listen, and he took Jeremiah before the officials.
They were furious with Jeremiah and had him flogged and imprisoned in the house of Jonathan the secretary. Jonathan's house had been converted into a prison.
Jeremiah was put into a dungeon cell, where he remained for many days.
Later King Zedekiah secretly requested that Jeremiah come to the palace, where the king asked him, "Do you have any messages from the LORD?" "Yes, I do!" said Jeremiah. "You will be defeated by the king of Babylon."
Then Jeremiah asked the king, "What crime have I committed? What have I done against you, your officials, or the people that I should be imprisoned like this?
Where are your prophets now who told you the king of Babylon would not attack you?
Listen, my lord the king, I beg you. Don't send me back to the dungeon in the house of Jonathan the secretary, for I will die there."
So King Zedekiah commanded that Jeremiah not be returned to the dungeon. Instead, he was imprisoned in the courtyard of the guard in the royal palace. The king also commanded that Jeremiah be given a loaf of fresh bread every day as long as there was any left in the city. So Jeremiah was put in the palace prison.