This Ayah is a call to all sinners, be they disbelievers or others, to repent and turn to Allah. This Ayah tells us that Allah, may He be blessed and exalted, will forgive all the sins of those who repent to Him and turn back to Him, no matter what or how many his sins are, even if they are like the foam of the sea. This cannot be interpreted as meaning that sins will be forgiven without repentance, because Shirk can only be forgiven for the one who repents from it. Al-Bukhari recorded that Ibn `Abbas, may Allah be pleased with him, said that some of the people of Shirk killed many people and committed Zina (illegal sexual acts) to a great extent; they came to Muhammad ﷺ and said, "What you are saying and calling us to is good; if only you could tell us that there is an expiation for what we have done." Then the following Ayat were revealed:
The next three verses (56-58), beginning from: أَن تَقُولَ نَفْسٌ يَا حَسْرَتَىٰ (Pity on me, because I fell short in respect of Allah... 39:56) and concluding on: مِنَ الْمُحْسِنِينَ (...become one of those who are good in deed - 39:58), have elaborated and emphasized the subject of the three verses earlier to it (53-55), that no sinner of any description should despair of the mercy of Allah, for should he repent, Allah will forgive all his past sins. But through the use of the expression: أَن تَقُولَ نَفْسٌ (lest someone should say) at the head of the three verses: 56, 57 and 58, it was reminded that the time of taubah has a deadline - it has to be well before death. If someone were to think of making his taubah after death on the Day of Judgment, or is simply filled with remorse over what awful things he had done to himself, then, that will bring him no benefit.
When those who possess sensitive hearts are blessed with a deep realisation of God (ma‘rifah), they start becoming worried as to what would happen about their past sins. Similarly, even after adopting a God-fearing way of life, a man is likely to display shortcomings from time to time, and his sensitive nature makes him worry again on this account. These feelings in some people can become so intense as to cause a deep sense of frustration. For such people, God has declared in His Book that they should firmly believe that their God is Forgiving and Merciful. He does not look at a man’s past but at his present. He does not look to his outward form but at his inner soul. He treats a man with broad-mindedness and not with petty-mindedness. That is why, when a man turns towards Him, He once again takes him into the fold of His Mercy, howsoever big a blunder the man might have committed.
Uthmani text of the Madinah mushaf (King Fahd Complex). Translation: Saheeh International. Tafsir via Quran.com.