He said to him, “Run and tell this young man: Jerusalem will be inhabited without walls because of the number of people and animals in it.” The declaration of the Lord: “I myself will be a wall of fire around it, and I will be the glory within it.”
-Zechariah 2:4-5 (CSB)
Zechariah, along with Haggai, were prophets sent by God to preach His word to the first post-exilic Jews that were returning to their homeland around 520 BC. Zechariah received numerous visions from God to relay messages back to Jerusalem. Notably, the book begins with God calling all His people to repent and return to Him (Zech 1:3-5). This was a rather difficult decision to make for Jews that had lived most of their lives in captivity to the Babylonians and Persians over the past 70 years. They were comfortable and well-situated in those countries and saw little reason to return to their homeland and face adversity. Therefore, the first exilic Jews that returned to Jerusalem were just a remnant, or precisely 42,360 people, of the entire population residing outside of the city (Ezra 2:64; Isaiah 10:20-21).
God had high expectations for his returning people and provided a vision to Zechariah saying that there was no need to survey Jerusalem's walls because of the "number of people and animals in it." God went so far as to tell Zechariah to promptly tell everyone that no walls were needed to be built in Jerusalem (Zech 2:4). Instead, God told Zechariah that He would be a wall of fire around it and that He would be Glorified in it (Zech 2:5). This was probably in response to their fear of the surrounding peoples (Ezra 3:3).
Besides post-exilic Jewish people refusing to return to Jerusalem to rebuild the second temple and the city, the ones that did return were met with much resistance and became discouraged (Ezra 4:1-4). It wasn't until Haggai began prophesying to the people in the second year of King Darius that the second temple would finally have been built (Ezra 5:1-2; Haggai 1:1). This meant that between the laying of the temple foundation and its full construction took about 20 years.
The people had become so complacent with finishing the work that they built houses for themselves while neglecting God's House. The LORD mentions to His people that while they lived comfortably, His House was in ruins (Hag 1:3) The saddest part about this all is that God told them to acquire lumber "up in the hills" instead of the high-quality cedar wood that was to be initially used for the temple that was authorized by King Cyrus (Ezra 3:7). The people used the choice cedar wood for their own housing projects.
About 80 years later, some 1800 people returned with Ezra (Ezra 8:1-20) to Jerusalem after the temple had already been built during Haggai and Zechariah's time (about 520 BC). They discovered that the first exilic Jews had not separated themselves from the surrounding nations and were intermarrying with foreigners--even up to the level of leaders and officials (Ezra 9:1-2). These practices greatly upset Ezra and we see his confession of prayer to God in subsequent verses of that chapter even to the point of tearing out parts of his hair and beard (Ezra 9:3).
This discovery shows that even some 80 years later the people were still prone to the same misdeeds and unfaithfulness just like their ancestors. But it didn't just stop there with just the Jews intermarrying foreigners. While Nehemiah is regarded as a champion of God's favor in the rebuilding of Jerusalem's walls, he clearly did not read about the vision Zechariah received from God about not building a wall around this Holy city (Zech 2:4-5). There were very good reasons for this wall to not be rebuilt and Scripture makes this point quite clear because of what had happened in the past when Jerusalem had a wall before going into captivity.
"Precisely because they have misled my people, saying, ‘Peace,’ when there is no peace, and because, when the people build a wall, these prophets smear it with whitewash, say to those who smear it with whitewash that it shall fall! There will be a deluge of rain, and you, O great hailstones, will fall, and a stormy wind break out. And when the wall falls, will it not be said to you, ‘Where is the coating with which you smeared it?’" -Ezekiel 13:10-12
Jerusalem trusted in having a wall like the surrounding nations did over trusting in God to protect them. These verses show false prophets telling Jerusalem that there was nothing to fear from Babylon's siege because they had strong defensive walls to protect them. God promises them that though they 'whitewash' or play down the siege, He will destroy Jerusalem's walls and these false prophets (Ezek 13:14-15).
Additionally, there are other references in Scripture that denote the false sense of security nations place in having walls as a means of protection. For instance, God destroyed the walls of Jericho in Joshua chapter 6 by commanding Israel to march around the city several times for one week (Joshua 6:1-6,20). In Ezekiel 26:4, God promises to destroy the walls of Tyre and destroy their defenses. Then in Daniel 5, while there is a siege outside of Babylon's walls, God literally writes on the "plaster of the wall" of the king's palace about King Belshazzar's impending death and fall of Babylon. This, of course, was prophesized in Isaiah 45 about Cyrus finding a way to break through the impenetrable walls of Babylon by "breaking in pieces the doors of bronze" and "cutting through the bars of iron" (Isaiah 45:2).
So then why would Nehemiah desire so much to the point of praying fervently to God that these walls be rebuilt in Jerusalem (Neh 4:1-10)? Most likely because of what having a wall meant during that time period for Jewish people. A wall represented established borders for sovereignty and solidification of Jews as a recognized people. It also protected them from outside threats and made a strong statement to surrounding nations that they were an established people blessed by God (Nehemiah 1:9, 2:20, 6:16)
There were many valid reasons for Jerusalem to have walls built around the city. However, Zechariah made it clear that God was to be their wall of fire and receive Glory from it (Zech 2:4-5). So, then the question must be asked, "If this wall rebuilding was against God's Will for His people, why then would He bless them in their effort to rebuild it?"
The short answer is that by the righteous prayer of one individual who was faithful in his love to God, The LORD demonstrated His Faithful Love to Nehemiah by allowing him to build up the walls of Jerusalem. This behavior is not unfamiliar to God's Character. David was not a perfect, upright man by his own account. He broke almost all ten commandments because of his affair with Bathsheba (2 Sam 11:4, 26). Yet, he was faithful in his love for God, and God counted this faithfulness as righteousness (1 Sam 13:14). Yes, even to the point of including David and Bathsheba's child, Solomon in the lineage of Jesus Christ (Matthew 1:6). It wasn't at all that God's Will was not accomplished, but that in His Faithful Love, He used sinful human beings to carry out His Will through them. Was this wall supposed to be built? No. Just like David wasn't supposed to have a son with Bathsheba. It's a beautiful understanding of God's faithfulness to us even when we act foolishly or even downright sinfully. Moreso, the fervent prayer of a righteous person can move God to act in such a faithfully loving way to demonstrate His rich mercy for us by including our desires (even when not completely right) in accordance with His Will, so that He may ultimately be Glorified.