An excellent question. Many devout Hindus have asked me this before, so I am pleased to post it here.
Firstly, know that there is a ‘revised’ Ramayana rewritten by a reformer named Tulsidas. Tulsidas’ version is much more steeped in strict cultural norms and hints of misogyny compared to the original. However, one should refer to the original Ramayana, written by Valmiki.
In original Ramayana, we see the very important phrase that is written before Lord Ram speaks before the court of monkeys and demons in Sita’s presence just as He has finally rescued Her:
"The heart of King Ram, as He saw Sita, the most beloved of His heart, near Him, was torn for fear of public scandal." -6.115.11 (Yuddha Kanda)
"The world would chatter against me, saying that Rama, the son of Dasaratha, was really foolish and that his mind was dominated by lust, if I accept Sita without examining her with regard to her chastity." -6.117.14 (Yuddha Kanda)
Lord Ram, though He risked His life to rescue His beloved Sita, knew His dharma in the end was to act as a righteous king. Lord Ram, Bhagvan, knows His dear Sita to be pure, as His divinity and deepness in love with Narayani transcends even human emotions, but the importance to display His kingliness in that very troubled time (the former King, Ravana, had just been destroyed, so it was His time to claim the kingdom), and being the son of a king, his place, so to say was to assume the position. He implored Her to escape scrutiny from the public eye, bound by the culture at that time.
"O Sita! That is why, I am permitting you now. Go wherever you like. All these ten directions are open to you, my dearest! There is nothing more to do." -6.114.17 (Yuddha Kanda)
Even then as we see here, as Lord Ram speaks about her impurity in front of the court of His new kingdom, He does not ask Her to prove anything by means of fire, pain or public humiliation. He only asks Her to leave for Her sake.
Upon hearing this, Sita’s love for Ram being overflowing and completely devoted, She offers Herself to the sacrificial fire willingly to prove Her point to an extreme. Ram is surprised by Her offer and is devastated. Before He is able to speak to Her in private, the public sets up the sacrificial fire.
Upon entering the flames, Sita exclaims to let Herself be saved from death by God to show Ram of her truthfulness. Ram cried as She entered the fire. Just as She does, the Gods arrive to the ordeal, asking why Ram does nothing while Sita immolates Herself. Ram replies that He foolishly thinks of Himself as just a human, bound to human culture and public eye.
Lord Brahma then speaks to Him, saying He is truly Lord Vishnu Narayana and Sita is no other than Maa Lakshmi Narayani. Sita is saved from death and Ram is overjoyed. They return to Ayodhya and claim their seats as king and queen.
I hope I’ve explained it well enough!
Jai Sia Ram!