Because the party membership voted for Truss instead of him - they get to choose between the top two candidates the MPs select. Party membership is a lot smaller group than primary voters in the U.S. Why did the party pick Truss? Maybe they were uncomfortable with having someone non-white. Maybe they thought Truss could connect better to the electorate. Maybe they preferred her policy ideas.
I suspect a lot of members voted against Sunak because they believe he shafted Boris Johnson, who remains popular with members. Plus, Truss did the whole Thatcher 2.0 thing, which appeals to many Tories. I don't think race played a significant role. In my experience, the people most opposed to Sunak adore Kemi Badenoch and Suella Braverman.