Ezra tore his clothes when he heard about the Israelites being unfaithful to God by disobeying the command not to intermarry with the other tribes and peoples who lived around them.
No one knows exactly where, when, or why this custom started, but many cultures have similar traditions of making some kind of small personal and tangible sacrifice as a way of expressing emotional loss and grief. The first tunic-tearing in the Bible is recorded in Genesis 37:29 when Reuben found out his younger brother Joseph was carried off to Egypt. The second is in verse 34 when Jacob tore his clothes upon hearing the lie that Joseph was dead. Other Old Testament robe rippers include David, Elisha, and Job. Even the apostle Paul, hundreds of years later, tore his clothes in despair (Acts 14:14). What do you do to show you’re sad?