The first reason that drives the ostrich to put its head in the ground is that it digs a hole in the ground to lay its eggs inside, and then from time to time inserts its head into that hole to check on the safety of its eggs.
As for the second reason, it is to protect itself from danger, by listening to the vibrations that reverberate in the ground from long distances due to the footsteps of dangerous animals, because they know very well that the transmission of sound in solid materials is much faster than its transmission in the air. As you can distinguish the direction from which these sounds come, this pushes them to flee in the direction that guarantees their safety, or they extend their body and neck on the ground to become like a pile of dirt or a bush to camouflage and protect themselves.
Finally, the third reason that drives the ostrich to put its head in the ground is its search for water, as its ability to hear things enables it to know the nearest place where there is water.