We know many people who have waited for years to have a child or to find their spouse.
What is a reason why Hashem does this?
This is not limited to these two examples, as it applies to other things one may need to wait for. These examples were chosen because they are more common.
Let’s take the example of a person waiting to have children. Part of the reason Hashem does this is because something greater is being formed through that waiting. For example, when someone davens for a child, those tefillos don’t go to waste. They become part of the spiritual makeup of the child who will eventually be born, shaping that child throughout their life. The wait itself contributes to a deeper outcome than would have been possible without it.
Another reason for the wait would be because the tefillos a person davens changes him. Consequently, whereas before the tefillos he wasn’t a receptacle to receive it, now he became a vessel for it.