Why did Sita walk into the fire?

After the war, Sita was free at last. But the reunion was not what she had dreamed.
Before the whole army, Rama said she had lived in another man's house. Heartbroken, Sita did not bow her head. She asked Lakshmana to build a fire, and walked into it.
The flames did not touch her. Agni, the god of fire, carried her out, and declared she had never been untrue. Rama said he had never doubted her, but the world needed to see it.
Source: Valmiki Ramayana. Episodes found only in later retellings are marked as such.