Many of us have heard this even in Hindi
Jo hota hain acha ke liye hota hain.
Is this concept found in any scriptures of Hinduism? Is this really part of Hindu philosophy or not? Is it shown anywhere in Ramayana or Mahabharata?
Indeed, prakṛti is equilibrium of the guṇas;
They are guṇas of prakṛti, not of ātman.
Known as sattva, rajas, and tamas,
Respectively, they cause sthiti, utpatty, and anta.
—Bhāgavata Purāṇa: Canto XI, Ch 12, Verse 12 (personal partial translation)
Undeniably, that which is material is a result of equilibrium among the Three Modes;
These are modes of the material, not of the spiritual.
Known as goodness-harmony, passion-dynamism, and ignorance-cacophony,
Respectively, they cause Cosmic Maintenance, Cosmic Generation, and Cosmic Annihilation.
Since maintenance of the material stems from goodness, the nature of the manifest world must be good, even if it seems in our judgement to be bad. Further, when ignorance leads to destruction, another generation event follows. Thereafter further maintenance is required.
For example, if a cow dies in the wilderness a kind of destruction has occurred. The corpse then decays and brings about the total annihilation of its form. This action of decay provides new life for bacteria, fungi, plants, larvae, scavengers, etc.
So, we can say that, while perhaps not all events are sattvam, sattva is the standard to which rajas and tamas must lead. For it is in sattva that things last. This is why we also call it harmony. Sattva is also translated as being-ness, is-ness, or the essence of existence. That which is not, has no sattva. Thus, everything which occurs, must have goodness as its nature. It is our ignorance which makes us perceive goodness as displeasing.
Evolution has made it easier for us to look for immediate rewards or pleasures and so we call these "good." Like children, we often forget that immediate discomfort may lead to better long-term results. This is why we fail to recognize the intrinsic goodness in all existing things.
Sorry I could not provide you with a more authoritative answer. Hopefully the logic I presented will suffice.
Please do correct any misspellings or diacritic mistakes I have made.
No, this verse is not likely to be found in traditional scriptures.
Because, it doesn't have any Sanskrit basis.
The Hindi line is usually wrongly attributed to "essence of Bhagavad Gita". Refer this answer.