Suma is in nominative.
Trzech and pięciu describe suma: literally, the sum of three and five. Where English uses of, Polish usually uses genitive.
Osiem is in nominative, because it's on the other side of to.
If you remove the nouns in genitive, you'll end up with this also correct sentence: suma to osiem the sum is eight, which is exactly the same form of sentence that was drilled during the early lessons.