Praise be to Allah, and peace and blessings be upon our master, the Messenger of Allah.
A prayer is not invalidated by minor movements, like taking a step or two. Imam al-Sharbini al-Shafi'i (may Allah have mercy on him) explains: "The prayer is not [invalidated by a minor action], even if done intentionally... According to the most correct view, what counts as 'minor' or 'major' is determined by customary practice (Urf). Whatever people typically consider minor—such as slipping off your footwear, putting on a light garment, or killing a louse—is overlooked. The author illustrated this by mentioning: taking two moderate steps, striking twice similarly, or gesturing to return a greeting. These are considered minor based on the prophetic tradition of removing one's sandals [during prayer]." [Mughni al-Muhtaj, Vol. 1/P.418]
On the flip side, excessive or major movement—generally defined as three or more consecutive movements, or moving a heavy limb (like the hand, foot, or head) three consecutive times without a valid need—will invalidate the prayer.
However, if it is done out of necessity, the prayer remains completely intact. The jurists of the Shafi'i school have permitted a praying person to move a heavy limb three times, even consecutively, if there is a pressing need, as long as they do not turn their chest away from the Qiblah (the direction of prayer).
Imam al-Sharqawi al-Shafi'i (may Allah have mercy on him) noted: "The prayer is not invalidated if someone moves their palm three times consecutively to scratch an itch out of necessity. It is deduced from this that if a person is afflicted with an involuntary movement that results in excessive physical action, it is forgiven." [Hashiyat al-Sharqawi 'ala Tuhfat al-Tullab, Vol. 1/P.221]
In conclusion, there is no sin on anyone who suffers from a sudden ailment during prayer—such as severe dizziness that could cause them to fall—if they make three movements, even consecutively, to steady themselves. Their prayer remains perfectly valid and is not nullified, because the action was driven by genuine necessity. And Allah the Almighty knows best.