I fully agree with Gustavo's convincing explanation, but I'd like to share with you another perspective I came across in a book entitled "Points of Modern English Syntax by P.A. Erades. Dr. Wood said in the book: "When "to" and "for" are interchangeable, the statement with "to" is made from the point of view of the person it relates to, while with "for", the statement is made from the speaker's point of view."
For example, It was a useful lesson for him. It means the speaker thinks it was a useful lesson for him. If we say it was a useful lesson to him, we mean from his point of view, it was a useful lesson. When we say: "Let that be a lesson to you," we mean you should realize it was a lesson you must learn from it. If we say: "That should be a lesson for you." we mean whether or not you realize you should learn a lesson, it was a lesson you should learn from it."