Why would God tell His prophet not to marry? It's a prophetic act revealing the bleakness of the future.
The context leading up to this verse (Jeremiah 16:1-4) reveals a divine command for Jeremiah not to marry or have children. This isn't a commentary on celibacy itself, but a profound prophetic sign.
If a prophet, someone intimately connected with God, is forbidden to perpetuate his family, it signals that there is no future worth building. God declares, through Jeremiah's personal life, that the land is doomed. To bring children into such a world, a world destined for destruction by disease, sword, and famine, would be to multiply sorrow. It shows the people that their lineage, their hope for continuation, is utterly cut off by God's judgment. Marriage and children represent life and hope; forbidding them signifies impending death and desolation.