Maliks Muwatta Book 3, Hadith Number 71.

Section : What to Do if One Stands After the Completion of the Prayer or After Two Rakas.

Yahya related to me from Malik from Yahya ibn Said from Abd ar-Rahman ibn Hurmuz that Abdullah ibn Buhayna said, “The Messenger of Allah, may Allah bless him and grant him peace, prayed dhuhr with us and he stood straight up after two rakas without sitting. When he had finished the prayer, he did two sajdas and then said the taslim after that.”

Malik said, concerning someone who forgot in his prayer and stood up after he had completed four rakas and recited and then went into ruku and then, when he raised his head from ruku, remembered that he had already completed (his prayer), “He returns to a sitting position and does not do any sajda. If he has already done one sajda I do not think he should do the other. Then when his prayer is finished he does two sajdas from the sitting position after saying the taslim.”