They get 9 ZEV credits for producing a hydrogen car. Whereas they can only get a max of 7 for EVs if they produce a 300-mile range car AND have battery swapping - with the cars they are building now, they only get 3 credits. With hydrogen they just have to build the cars, and have the state of CA pay immense amounts of money to install hydrogen stations. That last "clean car" suite of bills that CA passed in September included lots of money for hydrogen stations thanks to persistent lobbyists - they same way that hydrogen cars got 9 credits. (I assume they will only be sold in CA; can't fuel them anywhere else).
For the compliance car manufacturers, this is really attractive. They are losing money for each car; by building hydrogen cars instead of EVs, they can lose 3x as much money per car and still come out even financially (actually better if they figure they can fill in the missing cars with gas cars) - and it doesn't honk off their dealers that don't want to take the time to explain charging to new customers.
They aren't trying to make the world a better place or even produce the best cars they can; they are trying to lose as little money as possible while continuing to sell gas cars. Given the CARB credit structure, hydrogen cars look attractive for that purpose. Plus hydrogen has always been further out than EVs, which meant they could push out sales of anything a long time as long as they kept saying hydrogen was close. In fact for many years, they got credits just for hydrogen research. This changed around 2008 or 2009; Nissan and BMW announced their electric car programs the next month. (Rather than just do compliance cars, they decided to try to make lemonade and make a business out of it. They are still conquest cars though, not meant to appeal to their existing customers). The Volt and Model S were already planned; they were the only cars that were not a result of this credit change (well, the Mitsubishi i-MiEV was around too; but only for Japan - it coming to the US was in response to the others announcing their EV programs).