A prophet said it out loud, in specifics

Zakariyya, peace be upon him, did not offer a general pious sentiment about the decree. He told Allah that his bones had weakened and his head had filled with white, that his wife could not bear children, and that he was afraid of who came after him.

That is a named, embodied, personal grief about not having a child, spoken plainly, and the Qur'an records it without a word of correction.

If you have been told that wanting this so much is a spiritual problem, the text is not on the side of the person who told you.

The report below is the one about affliction wiping away sins. It is often deployed to end a conversation, as though you should now be pleased. That is not what it does. It says something about what suffering means. It does not say the grief is finished, and it is not an answer to anyone's question about how you are.

Qur’an and Sunnah

ذِكۡرُ رَحۡمَتِ رَبِّكَ عَبۡدَهُۥ زَكَرِيَّآ

This is an account of your Lord’s grace towards His servant, Zachariah

Qur’an 19:2

إِذۡ نَادَىٰ رَبَّهُۥ نِدَآءً خَفِيࣰّ ا

when he called to his Lord secretly, saying

Qur’an 19:3

قَالَ رَبِّ إِنِّي وَهَنَ ٱلۡعَظۡمُ مِنِّي وَٱشۡتَعَلَ ٱلرَّأۡسُ شَيۡبࣰ ا وَلَمۡ أَكُنۢ بِدُعَآئِكَ رَبِّ شَقِيࣰّ ا

‘Lord, my bones have weakened and my hair is ashen grey, but never, Lord, have I ever prayed to You in vain

Qur’an 19:4

وَإِنِّي خِفۡتُ ٱلۡمَوَٰلِيَ مِن وَرَآءِي وَكَانَتِ ٱمۡرَأَتِي عَاقِرࣰ ا فَهَبۡ لِي مِن لَّدُنكَ وَلِيࣰّ ا

I fear [what] my kinsmen [will do] when I am gone, for my wife is barren, so grant me a successor––a gift from You––

Qur’an 19:5

يَرِثُنِي وَيَرِثُ مِنۡ ءَالِ يَعۡقُوبَۖ وَٱجۡعَلۡهُ رَبِّ رَضِيࣰّ ا

to be my heir and the heir of the family of Jacob. Lord, make him well pleasing [to You].’

Qur’an 19:6

Narrated Abu Sa`id Al-Khudri and Abu Huraira:The Prophet (ﷺ) said, "No fatigue, nor disease, nor sorrow, nor sadness, nor hurt, nor distress befalls a Muslim, even if it were the prick he receives from a thorn, but that Allah expiates some of his sins for that

Sahih al-Bukhari 5641graded sound, sahihaynfull report

Translation: M.A.S. Abdel Haleem, The Qur'an, Oxford University Press, 2004.