Why do some people get costochondritis and others don't?

Usually viral illnes. Costochondritis, or tietze's syndrome, is an inflammation of the costochondral junction along the anterior chestwall adjacent to the sternum. It is usually caused by a viral illness, and like all viral illnesses who gets it is hard to predict. No genetic predisposition has been suggested. A strong immune system is probably the best defense, i.e., good rest, good nutrition, etc.
You've been lucky. Inflammation of the front of the rib cage where it meets your chest bone-sternum. It has connections formed of cartilage. The cause can be many things. One of course is potentially viral, also indirectly a bacterial infection causing a patient to cough so much the movement of their ribs is irritated. Immune deficiency diseases as sarcoid; other causes as trauma and curvature of spine incr chance.