Srila Prabhupada here explains the exact reason why demon Kamsa who always wanted to kill Krishna attained liberation.
We have seen in the history of India that Aurangzeb killed his brother and nephews and imprisoned his father to fulfill political ambitions. There have been many similar instances, and Kamsa was the same type of king. Kamsa did not hesitate to kill his nephews and imprison his sister and his father. For demons to do such things is not astonishing. Nonetheless, although Kamsa was a demon, he was aware that Lord Visnu cannot be killed, and thus he attained salvation. Even partial understanding of the activities of Lord Visnu makes one eligible for salvation. Kamsa knew a little about Krsna -- that He could not be killed -- and therefore he attained salvation although he thought of Visnu, Krsna, as an enemy. What then is to be said of one who knows Krsna perfectly from the descriptions of sastras like Bhagavad-gita? It is therefore the duty of everyone to read Bhagavad-gita and understand Krsna perfectly. This will make one's life successful.
SB 10.1.67 purport