From ancient time, work has been divided between people according to the cast. As Kshatriya for defence system, bramins for knowledgeable things like yagya, worship, & other religious things which needs deep knowledge, etc. With this system, the work they & their ancesstors did goes into their DNA. So, as the child born in Kshatriya family will be good in wars & same as of bramins, shudras.
As, Karna was born from a Kshatriya woman, he got the DNA & tolerance power of Kshatriyas. By looking at the tolerance power of Karna, Acharya Parshuram called him a Kshatriya & told that he cheated him & given the curse. According to him, only Kshatriya contains this much power of tolerance. So, as Karna was a born Kshatriya, he became a great warrior, since it is in his DNA.
So, from ancient time, people do marriage in their own caste.