It is quite likely that the people were afraid of the nations surrounding them. God’s people at this point were a struggling province on the edge of the great Persian empire. Certainly in the early days of the leadership of Zerubbabel and Joshua there was fear (Ezra 3:3; Ezra 4:4–5), and it is quite possible that this fear continued. So the prophet is called to encourage the people away from fear, and he does so through the command that falls within a context of declaring the promise of God to be in their midst.1
Notably, this exhortation comes after the notice in Haggai 1:12 that the people feared the Lord.
This highlights that there is a right sort of fear, one that is the beginning of wisdom (Proverbs 1:7) and identifies the child of God (1 Peter 1:17). It is a fear that lets one in fact enjoy the promises and presence of the Lord, and face the future, all without fear.2
5 according to the covenant that I made with you when you came out of Egypt. My Spirit remains in your midst. Fear not.