It is obligatory to pray facing a sutrah (a screen, barrier, wall, or object ahead of the place of prostration) when performing the prayer. The sutrah acts as a barrier between yourself and others when praying; it also allows others to walk in front of you, as long as the object is between you and them.
The Prophet (may the peace and blessings of Allah be upon him) said:
"Do not pray except towards a sutrah, and do not let anyone pass in front of you, but if someone continues (to try to pass) then fight him, for he has a companion (i.e., a devil) with him." [Ibn Mājah: 954]
The sutrah should be approximately an forearm's length above the ground, because the Prophet (may the peace and blessings of Allah be upon him) said:
"When one of you places in front of him something such as the stick on the end of a saddle, he should pray and not worry about anyone who passes in front of that." [at-Tirmidhī: 335]
Even though a person's prayer does not normally get invalidated if the person does not place a sutrah in front of them, there are certain situations when it is invalidated.
The Prophet (may the peace and blessings of Allah be upon him) said:
"A man's prayer is cut off when there is nothing such as the end of a saddle in front of him, by: a woman [who reached puberty], a donkey or a black dog..." [Ibn Mājah: 952]
From the above narration, when no sutrah is used, the three mentioned things passing in front of the worshipper nullify the prayer. The wisdom behind such nullification is with Allah the Most High.