Great question. As you said, both mean to understand, but they do imply different ways one understands thing in different contexts.
Let’s first breakdown 理解 and 了解. Then look at some example sentences.
理解 can be further translated and explain as “to understand one’s logic, to understand the logic of something” 理 being the 理 in 道理.
了解 can be expanded to mean “to fully understand”. The 了 in 了解 means “end” in classical Chinese. So you could think of it as to come full circle, you are at the end of your comprehension process and you now understand. Or in other words 你懂了.
Now, let’s see what this all means…
了解 is used more frequently in day to day conversation. When some explains something to you and you want to say that you’ve “got it”, you would say "了解”.
理解 is used when you want to place emphasis on the logic or the comprehension process of something. In many cases it can be translated as one’s comprehension ability or empathy.
Let’s look at a case where they are interchangeable:
“I understand why he is so angry”
If you wanted a more in depth translation you could say that a) “I can empathize with” and b) I really get. With a) you’re saying that you understand his logic as to why his angry and with b) you could perhaps say you not only logically understand but emotionally also, you really “get it”.
Now let’s look at cases where they are not interchangeable:
- 他的理解能力很强 - His ability to comprehend is very strong.
- 这篇文章太学术，一般人没办法理解。 - This academic article is “too academic”, most people won’t be able to understand it.
Both of the above cases you cannot use 了解, as the focus is on the ability to comprehend.
你都不了解我 - You don’t get me at all.
发生了什么事，你去了解一下状况 - What’s happened? Go see what’s up?
The above examples are also not interchangeable also. The first being that it’s somewhat leaning more towards the emotional rather than the logical. The second sentence the speaker wants the other person to fully understand the situation. The focus is not on the process of understanding.
Hope that clarifies things a little more and let me know if there is anything you’d like me to expand on.