Maybe Roberts wrote both opinions? My speculation at least answers the question as to why.
Did you even read Kennedy’s dissent? If what you say is true, then Kennedy was going to uphold the mandate on the basis of the Commerce Clause, but then, he switches with Roberts and suddenly does a 180 to argue in favor of striking the *entire* (not just the mandate) law. Sure.