Dear Zafreen,
As-salamu alaykum
Notwithstanding fasting in the way to seek the pleasure / mercy of God - to learn self-restraint and to thank Him (2:185), fasting is also one of the ways a believer can seek redemption / expiation no different from offering charity or sacrifice. It is not simply a punishment but a mechanism / avenue to seek atonement.
'...then a ransom of fasting or charity or sacrifice...' (2:196)
As another example, if you note verse 5:95, a penalty is cited for killing game on Hajj. One is to make an offering of a similar animal. If this is not possible, then in the same verse, there is another expiation (kaffara); that is of feeding the poor or an equivalent recompense (adhlu). The equivalent recompense given is fasting.
I hope this helps, God willing,
Joseph