Kant does not claim that “all mathematical judgments are both a priori and contingent (synthetic).”
For Kant, all a priori truths are necessary truths, including a priori synthetic truths.
Prior to Kant the empiricists had believed that what Kant called synthetic judgements were not a priori judgements, that they were empirical judgements. Kant argued that if metaphysics is to be possible, then a priori synthetic knowledge must be possible and the example he gave was that of geometry. Thus, for Kant, geometry is a priori, necessary, and universal - i.e., in no way contingent.
It is important to keep in mind here that Kant is writing at a time when nobody had thought of the idea that there could be other geometries. For Kant there was one geometry - Euclidean geometry - and it was a priori and synthetic.
You may have some confusion about Kant’s use of the word synthetic. Kant thought of analytic judgements as those where the concept of the predicate is contained in the concept of the subject and synthetic judgements as those where this is not the case.
For example, if we define a triangle as a three-sided figure in the plane, then the statement “A triangle has three sides” is analytic since the concept of a triangle contains the concept of it having three sides. On the other hand, the statement “The interior angles of a triangle add up to 180 degrees” is synthetic since our concept of a triangle as a three-sided figure does not include the concept of it having interior angles that sum to 180 degrees.
Rightly or wrongly, I like to think of it like this: a priori synthetic judgements are the synthesis of our concepts and our reasoning, while a posteriori synthetic judgements are the synthesis of our empirical considerations, our concepts, and our reasoning.